1994-05-27 05:00:24 +00:00
|
|
|
/*-
|
2017-11-20 19:49:47 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1994-05-27 05:00:24 +00:00
|
|
|
* Copyright (c) 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Sean Eric Fagan of Cygnus Support.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-27 05:00:24 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2002-02-01 00:57:29 +00:00
|
|
|
#include <sys/cdefs.h>
|
2018-07-03 17:31:45 +00:00
|
|
|
__SCCSID("@(#)sysconf.c 8.2 (Berkeley) 3/20/94");
|
2002-02-01 00:57:29 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
2001-06-18 20:24:54 +00:00
|
|
|
|
2015-12-20 23:05:20 +00:00
|
|
|
#include "namespace.h"
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <sys/param.h>
|
1995-12-08 08:47:41 +00:00
|
|
|
#include <sys/time.h>
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/resource.h>
|
2002-10-27 18:03:02 +00:00
|
|
|
#include <sys/socket.h>
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2012-06-27 20:32:45 +00:00
|
|
|
#include <elf.h>
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <errno.h>
|
2002-09-21 02:14:04 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include <pthread.h> /* we just need the limits */
|
2017-04-12 19:27:14 +00:00
|
|
|
#include <semaphore.h>
|
1995-02-03 22:28:34 +00:00
|
|
|
#include <time.h>
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <unistd.h>
|
2015-12-20 23:05:20 +00:00
|
|
|
#include "un-namespace.h"
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2002-09-21 02:14:04 +00:00
|
|
|
#include "../stdlib/atexit.h"
|
2010-02-26 06:44:00 +00:00
|
|
|
#include "tzfile.h" /* from ../../../contrib/tzcode/stdtime */
|
2012-06-27 20:32:45 +00:00
|
|
|
#include "libc_private.h"
|
2002-09-21 02:14:04 +00:00
|
|
|
|
|
|
|
#define _PATH_ZONEINFO TZDIR /* from tzfile.h */
|
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
/*
|
|
|
|
* sysconf --
|
|
|
|
* get configurable system variables.
|
|
|
|
*
|
|
|
|
* XXX
|
|
|
|
* POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values
|
|
|
|
* not change during the lifetime of the calling process. This would seem
|
|
|
|
* to require that any change to system limits kill all running processes.
|
|
|
|
* A workaround might be to cache the values when they are first retrieved
|
|
|
|
* and then simply return the cached value on subsequent calls. This is
|
|
|
|
* less useful than returning up-to-date values, however.
|
|
|
|
*/
|
|
|
|
long
|
2015-09-20 20:23:16 +00:00
|
|
|
sysconf(int name)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
|
|
|
struct rlimit rl;
|
|
|
|
size_t len;
|
2002-09-21 02:14:04 +00:00
|
|
|
int mib[2], sverrno, value;
|
2007-04-14 13:06:57 +00:00
|
|
|
long lvalue, defaultresult;
|
2002-09-21 02:14:04 +00:00
|
|
|
const char *path;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
1998-06-01 20:58:03 +00:00
|
|
|
defaultresult = -1;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
switch (name) {
|
|
|
|
case _SC_ARG_MAX:
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_ARGMAX;
|
|
|
|
break;
|
|
|
|
case _SC_CHILD_MAX:
|
2002-09-21 02:14:04 +00:00
|
|
|
if (getrlimit(RLIMIT_NPROC, &rl) != 0)
|
|
|
|
return (-1);
|
|
|
|
if (rl.rlim_cur == RLIM_INFINITY)
|
|
|
|
return (-1);
|
|
|
|
if (rl.rlim_cur > LONG_MAX) {
|
|
|
|
errno = EOVERFLOW;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return ((long)rl.rlim_cur);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_CLK_TCK:
|
|
|
|
return (CLK_TCK);
|
|
|
|
case _SC_NGROUPS_MAX:
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_NGROUPS;
|
|
|
|
break;
|
|
|
|
case _SC_OPEN_MAX:
|
2002-09-21 02:14:04 +00:00
|
|
|
if (getrlimit(RLIMIT_NOFILE, &rl) != 0)
|
|
|
|
return (-1);
|
|
|
|
if (rl.rlim_cur == RLIM_INFINITY)
|
|
|
|
return (-1);
|
|
|
|
if (rl.rlim_cur > LONG_MAX) {
|
|
|
|
errno = EOVERFLOW;
|
|
|
|
return (-1);
|
|
|
|
}
|
2008-02-27 05:56:57 +00:00
|
|
|
return ((long)rl.rlim_cur);
|
|
|
|
case _SC_STREAM_MAX:
|
|
|
|
if (getrlimit(RLIMIT_NOFILE, &rl) != 0)
|
|
|
|
return (-1);
|
|
|
|
if (rl.rlim_cur == RLIM_INFINITY)
|
|
|
|
return (-1);
|
|
|
|
if (rl.rlim_cur > LONG_MAX) {
|
|
|
|
errno = EOVERFLOW;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* struct __sFILE currently has a limitation that
|
|
|
|
* file descriptors must fit in a signed short.
|
|
|
|
* This doesn't precisely capture the letter of POSIX
|
|
|
|
* but approximates the spirit.
|
|
|
|
*/
|
|
|
|
if (rl.rlim_cur > SHRT_MAX)
|
|
|
|
return (SHRT_MAX);
|
|
|
|
|
2002-09-21 02:14:04 +00:00
|
|
|
return ((long)rl.rlim_cur);
|
|
|
|
case _SC_JOB_CONTROL:
|
|
|
|
return (_POSIX_JOB_CONTROL);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_SAVED_IDS:
|
2002-09-21 02:14:04 +00:00
|
|
|
/* XXX - must be 1 */
|
1994-05-27 05:00:24 +00:00
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_SAVED_IDS;
|
|
|
|
goto yesno;
|
|
|
|
case _SC_VERSION:
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_POSIX1;
|
|
|
|
break;
|
|
|
|
case _SC_BC_BASE_MAX:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (BC_BASE_MAX);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_BC_DIM_MAX:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (BC_DIM_MAX);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_BC_SCALE_MAX:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (BC_SCALE_MAX);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_BC_STRING_MAX:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (BC_STRING_MAX);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_COLL_WEIGHTS_MAX:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (COLL_WEIGHTS_MAX);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_EXPR_NEST_MAX:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (EXPR_NEST_MAX);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_LINE_MAX:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (LINE_MAX);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_RE_DUP_MAX:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (RE_DUP_MAX);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_2_VERSION:
|
2002-09-21 02:14:04 +00:00
|
|
|
/*
|
|
|
|
* This is something of a lie, but it would be silly at
|
|
|
|
* this point to try to deduce this from the contents
|
|
|
|
* of the filesystem.
|
|
|
|
*/
|
|
|
|
return (_POSIX2_VERSION);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_2_C_BIND:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX2_C_BIND);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_2_C_DEV:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX2_C_DEV);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_2_CHAR_TERM:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX2_CHAR_TERM);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_2_FORT_DEV:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX2_FORT_DEV);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_2_FORT_RUN:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX2_FORT_RUN);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_2_LOCALEDEF:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX2_LOCALEDEF);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_2_SW_DEV:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX2_SW_DEV);
|
1994-05-27 05:00:24 +00:00
|
|
|
case _SC_2_UPE:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX2_UPE);
|
|
|
|
case _SC_TZNAME_MAX:
|
|
|
|
path = _PATH_ZONEINFO;
|
|
|
|
do_NAME_MAX:
|
|
|
|
sverrno = errno;
|
|
|
|
errno = 0;
|
2007-04-14 13:06:57 +00:00
|
|
|
lvalue = pathconf(path, _PC_NAME_MAX);
|
|
|
|
if (lvalue == -1 && errno != 0)
|
2002-09-21 02:14:04 +00:00
|
|
|
return (-1);
|
|
|
|
errno = sverrno;
|
2007-04-14 13:06:57 +00:00
|
|
|
return (lvalue);
|
1998-03-04 10:27:00 +00:00
|
|
|
|
|
|
|
case _SC_ASYNCHRONOUS_IO:
|
2002-10-27 18:03:02 +00:00
|
|
|
#if _POSIX_ASYNCHRONOUS_IO == 0
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO;
|
2002-10-27 18:03:02 +00:00
|
|
|
break;
|
|
|
|
#else
|
|
|
|
return (_POSIX_ASYNCHRONOUS_IO);
|
|
|
|
#endif
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_MAPPED_FILES:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX_MAPPED_FILES);
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_MEMLOCK:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX_MEMLOCK);
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_MEMLOCK_RANGE:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX_MEMLOCK_RANGE);
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_MEMORY_PROTECTION:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX_MEMORY_PROTECTION);
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_MESSAGE_PASSING:
|
2002-09-21 02:14:04 +00:00
|
|
|
#if _POSIX_MESSAGE_PASSING == 0
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_MESSAGE_PASSING;
|
1998-03-04 10:27:00 +00:00
|
|
|
goto yesno;
|
2002-09-21 02:14:04 +00:00
|
|
|
#else
|
|
|
|
return (_POSIX_MESSAGE_PASSING);
|
|
|
|
#endif
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_PRIORITIZED_IO:
|
2002-09-21 02:14:04 +00:00
|
|
|
#if _POSIX_PRIORITIZED_IO == 0
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_PRIORITIZED_IO;
|
1998-03-04 10:27:00 +00:00
|
|
|
goto yesno;
|
2002-09-21 02:14:04 +00:00
|
|
|
#else
|
|
|
|
return (_POSIX_PRIORITIZED_IO);
|
|
|
|
#endif
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_PRIORITY_SCHEDULING:
|
2002-09-21 02:14:04 +00:00
|
|
|
#if _POSIX_PRIORITY_SCHEDULING == 0
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING;
|
1998-03-04 10:27:00 +00:00
|
|
|
goto yesno;
|
2002-09-21 02:14:04 +00:00
|
|
|
#else
|
|
|
|
return (_POSIX_PRIORITY_SCHEDULING);
|
|
|
|
#endif
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_REALTIME_SIGNALS:
|
2002-09-21 02:14:04 +00:00
|
|
|
#if _POSIX_REALTIME_SIGNALS == 0
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_REALTIME_SIGNALS;
|
1998-03-04 10:27:00 +00:00
|
|
|
goto yesno;
|
2002-09-21 02:14:04 +00:00
|
|
|
#else
|
|
|
|
return (_POSIX_REALTIME_SIGNALS);
|
|
|
|
#endif
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_SEMAPHORES:
|
2002-09-21 02:14:04 +00:00
|
|
|
#if _POSIX_SEMAPHORES == 0
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_SEMAPHORES;
|
1998-03-04 10:27:00 +00:00
|
|
|
goto yesno;
|
2002-09-21 02:14:04 +00:00
|
|
|
#else
|
|
|
|
return (_POSIX_SEMAPHORES);
|
|
|
|
#endif
|
|
|
|
case _SC_FSYNC:
|
|
|
|
return (_POSIX_FSYNC);
|
|
|
|
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_SHARED_MEMORY_OBJECTS:
|
2002-09-21 02:14:04 +00:00
|
|
|
return (_POSIX_SHARED_MEMORY_OBJECTS);
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_SYNCHRONIZED_IO:
|
2002-09-21 02:14:04 +00:00
|
|
|
#if _POSIX_SYNCHRONIZED_IO == 0
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO;
|
1998-03-04 10:27:00 +00:00
|
|
|
goto yesno;
|
2002-09-21 02:14:04 +00:00
|
|
|
#else
|
|
|
|
return (_POSIX_SYNCHRONIZED_IO);
|
|
|
|
#endif
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_TIMERS:
|
2002-09-21 02:14:04 +00:00
|
|
|
#if _POSIX_TIMERS == 0
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_TIMERS;
|
1998-03-04 10:27:00 +00:00
|
|
|
goto yesno;
|
2002-09-21 02:14:04 +00:00
|
|
|
#else
|
|
|
|
return (_POSIX_TIMERS);
|
|
|
|
#endif
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_AIO_LISTIO_MAX:
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_AIO_LISTIO_MAX;
|
2002-11-17 08:54:29 +00:00
|
|
|
break;
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_AIO_MAX:
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_AIO_MAX;
|
2002-11-17 08:54:29 +00:00
|
|
|
break;
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_AIO_PRIO_DELTA_MAX:
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX;
|
2002-11-17 08:54:29 +00:00
|
|
|
break;
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_DELAYTIMER_MAX:
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_DELAYTIMER_MAX;
|
1998-03-04 10:27:00 +00:00
|
|
|
goto yesno;
|
|
|
|
case _SC_MQ_OPEN_MAX:
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_MQ_OPEN_MAX;
|
1998-03-04 10:27:00 +00:00
|
|
|
goto yesno;
|
|
|
|
case _SC_PAGESIZE:
|
2018-11-19 18:23:17 +00:00
|
|
|
return (getpagesize());
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_RTSIG_MAX:
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_RTSIG_MAX;
|
1998-03-04 10:27:00 +00:00
|
|
|
goto yesno;
|
|
|
|
case _SC_SEM_NSEMS_MAX:
|
2017-04-12 19:27:14 +00:00
|
|
|
return (-1);
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_SEM_VALUE_MAX:
|
2017-04-12 19:27:14 +00:00
|
|
|
return (SEM_VALUE_MAX);
|
1998-03-04 10:27:00 +00:00
|
|
|
case _SC_SIGQUEUE_MAX:
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_SIGQUEUE_MAX;
|
1998-03-04 10:27:00 +00:00
|
|
|
goto yesno;
|
|
|
|
case _SC_TIMER_MAX:
|
1998-03-28 11:51:01 +00:00
|
|
|
mib[0] = CTL_P1003_1B;
|
|
|
|
mib[1] = CTL_P1003_1B_TIMER_MAX;
|
2007-04-14 13:06:57 +00:00
|
|
|
yesno:
|
|
|
|
len = sizeof(value);
|
|
|
|
if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
|
2002-09-21 02:14:04 +00:00
|
|
|
return (-1);
|
|
|
|
if (value == 0)
|
|
|
|
return (defaultresult);
|
2007-04-14 13:06:57 +00:00
|
|
|
return ((long)value);
|
2002-07-15 20:42:05 +00:00
|
|
|
|
2002-09-21 02:14:04 +00:00
|
|
|
case _SC_2_PBS:
|
|
|
|
case _SC_2_PBS_ACCOUNTING:
|
|
|
|
case _SC_2_PBS_CHECKPOINT:
|
|
|
|
case _SC_2_PBS_LOCATE:
|
|
|
|
case _SC_2_PBS_MESSAGE:
|
|
|
|
case _SC_2_PBS_TRACK:
|
|
|
|
#if _POSIX2_PBS == 0
|
|
|
|
#error "don't know how to determine _SC_2_PBS"
|
|
|
|
/*
|
|
|
|
* This probably requires digging through the filesystem
|
|
|
|
* to see if the appropriate package has been installed.
|
|
|
|
* Since we don't currently support this option at all,
|
|
|
|
* it's not worth the effort to write the code now.
|
|
|
|
* Figuring out which of the sub-options are supported
|
|
|
|
* would be even more difficult, so it's probably easier
|
|
|
|
* to always say ``no''.
|
|
|
|
*/
|
|
|
|
#else
|
|
|
|
return (_POSIX2_PBS);
|
2001-12-01 12:07:42 +00:00
|
|
|
#endif
|
2002-09-21 02:14:04 +00:00
|
|
|
case _SC_ADVISORY_INFO:
|
|
|
|
#if _POSIX_ADVISORY_INFO == 0
|
|
|
|
#error "_POSIX_ADVISORY_INFO"
|
|
|
|
#else
|
|
|
|
return (_POSIX_ADVISORY_INFO);
|
|
|
|
#endif
|
|
|
|
case _SC_BARRIERS:
|
|
|
|
#if _POSIX_BARRIERS == 0
|
|
|
|
#error "_POSIX_BARRIERS"
|
|
|
|
#else
|
|
|
|
return (_POSIX_BARRIERS);
|
|
|
|
#endif
|
|
|
|
case _SC_CLOCK_SELECTION:
|
|
|
|
#if _POSIX_CLOCK_SELECTION == 0
|
|
|
|
#error "_POSIX_CLOCK_SELECTION"
|
|
|
|
#else
|
|
|
|
return (_POSIX_CLOCK_SELECTION);
|
|
|
|
#endif
|
|
|
|
case _SC_CPUTIME:
|
|
|
|
return (_POSIX_CPUTIME);
|
|
|
|
#ifdef notdef
|
|
|
|
case _SC_FILE_LOCKING:
|
|
|
|
/*
|
|
|
|
* XXX - The standard doesn't tell us how to define
|
|
|
|
* _POSIX_FILE_LOCKING, so we can't answer this one.
|
|
|
|
*/
|
|
|
|
#endif
|
2014-07-09 19:12:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* SUSv4tc1 says the following about _SC_GETGR_R_SIZE_MAX and
|
|
|
|
* _SC_GETPW_R_SIZE_MAX:
|
|
|
|
* Note that sysconf(_SC_GETGR_R_SIZE_MAX) may return -1 if
|
|
|
|
* there is no hard limit on the size of the buffer needed to
|
|
|
|
* store all the groups returned.
|
|
|
|
*/
|
2002-09-21 02:14:04 +00:00
|
|
|
case _SC_GETGR_R_SIZE_MAX:
|
|
|
|
case _SC_GETPW_R_SIZE_MAX:
|
2014-07-09 19:12:18 +00:00
|
|
|
return (-1);
|
2002-09-21 02:14:04 +00:00
|
|
|
case _SC_HOST_NAME_MAX:
|
|
|
|
return (MAXHOSTNAMELEN - 1); /* does not include \0 */
|
|
|
|
case _SC_LOGIN_NAME_MAX:
|
|
|
|
return (MAXLOGNAME);
|
|
|
|
case _SC_MONOTONIC_CLOCK:
|
|
|
|
#if _POSIX_MONOTONIC_CLOCK == 0
|
|
|
|
#error "_POSIX_MONOTONIC_CLOCK"
|
|
|
|
#else
|
|
|
|
return (_POSIX_MONOTONIC_CLOCK);
|
|
|
|
#endif
|
|
|
|
#if _POSIX_MESSAGE_PASSING > -1
|
|
|
|
case _SC_MQ_PRIO_MAX:
|
|
|
|
return (MQ_PRIO_MAX);
|
|
|
|
#endif
|
|
|
|
case _SC_READER_WRITER_LOCKS:
|
|
|
|
return (_POSIX_READER_WRITER_LOCKS);
|
|
|
|
case _SC_REGEXP:
|
|
|
|
return (_POSIX_REGEXP);
|
|
|
|
case _SC_SHELL:
|
|
|
|
return (_POSIX_SHELL);
|
|
|
|
case _SC_SPAWN:
|
|
|
|
return (_POSIX_SPAWN);
|
|
|
|
case _SC_SPIN_LOCKS:
|
|
|
|
return (_POSIX_SPIN_LOCKS);
|
|
|
|
case _SC_SPORADIC_SERVER:
|
|
|
|
#if _POSIX_SPORADIC_SERVER == 0
|
|
|
|
#error "_POSIX_SPORADIC_SERVER"
|
|
|
|
#else
|
|
|
|
return (_POSIX_SPORADIC_SERVER);
|
|
|
|
#endif
|
|
|
|
case _SC_THREAD_ATTR_STACKADDR:
|
|
|
|
return (_POSIX_THREAD_ATTR_STACKADDR);
|
|
|
|
case _SC_THREAD_ATTR_STACKSIZE:
|
|
|
|
return (_POSIX_THREAD_ATTR_STACKSIZE);
|
|
|
|
case _SC_THREAD_CPUTIME:
|
|
|
|
return (_POSIX_THREAD_CPUTIME);
|
|
|
|
case _SC_THREAD_DESTRUCTOR_ITERATIONS:
|
|
|
|
return (PTHREAD_DESTRUCTOR_ITERATIONS);
|
|
|
|
case _SC_THREAD_KEYS_MAX:
|
|
|
|
return (PTHREAD_KEYS_MAX);
|
|
|
|
case _SC_THREAD_PRIO_INHERIT:
|
|
|
|
return (_POSIX_THREAD_PRIO_INHERIT);
|
|
|
|
case _SC_THREAD_PRIO_PROTECT:
|
|
|
|
return (_POSIX_THREAD_PRIO_PROTECT);
|
|
|
|
case _SC_THREAD_PRIORITY_SCHEDULING:
|
|
|
|
return (_POSIX_THREAD_PRIORITY_SCHEDULING);
|
|
|
|
case _SC_THREAD_PROCESS_SHARED:
|
|
|
|
return (_POSIX_THREAD_PROCESS_SHARED);
|
|
|
|
case _SC_THREAD_SAFE_FUNCTIONS:
|
|
|
|
return (_POSIX_THREAD_SAFE_FUNCTIONS);
|
|
|
|
case _SC_THREAD_STACK_MIN:
|
|
|
|
return (PTHREAD_STACK_MIN);
|
|
|
|
case _SC_THREAD_THREADS_MAX:
|
|
|
|
return (PTHREAD_THREADS_MAX); /* XXX wrong type! */
|
|
|
|
case _SC_TIMEOUTS:
|
|
|
|
return (_POSIX_TIMEOUTS);
|
|
|
|
case _SC_THREADS:
|
|
|
|
return (_POSIX_THREADS);
|
|
|
|
case _SC_TRACE:
|
|
|
|
#if _POSIX_TRACE == 0
|
|
|
|
#error "_POSIX_TRACE"
|
|
|
|
/* While you're implementing this, also do the ones below. */
|
|
|
|
#else
|
|
|
|
return (_POSIX_TRACE);
|
|
|
|
#endif
|
|
|
|
#if _POSIX_TRACE > -1
|
|
|
|
case _SC_TRACE_EVENT_FILTER:
|
|
|
|
return (_POSIX_TRACE_EVENT_FILTER);
|
|
|
|
case _SC_TRACE_INHERIT:
|
|
|
|
return (_POSIX_TRACE_INHERIT);
|
|
|
|
case _SC_TRACE_LOG:
|
|
|
|
return (_POSIX_TRACE_LOG);
|
|
|
|
#endif
|
|
|
|
case _SC_TTY_NAME_MAX:
|
|
|
|
path = _PATH_DEV;
|
|
|
|
goto do_NAME_MAX;
|
|
|
|
case _SC_TYPED_MEMORY_OBJECTS:
|
|
|
|
#if _POSIX_TYPED_MEMORY_OBJECTS == 0
|
|
|
|
#error "_POSIX_TYPED_MEMORY_OBJECTS"
|
|
|
|
#else
|
|
|
|
return (_POSIX_TYPED_MEMORY_OBJECTS);
|
|
|
|
#endif
|
|
|
|
case _SC_V6_ILP32_OFF32:
|
|
|
|
#if _V6_ILP32_OFF32 == 0
|
|
|
|
if (sizeof(int) * CHAR_BIT == 32 &&
|
|
|
|
sizeof(int) == sizeof(long) &&
|
|
|
|
sizeof(long) == sizeof(void *) &&
|
|
|
|
sizeof(void *) == sizeof(off_t))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
#else
|
|
|
|
return (_V6_ILP32_OFF32);
|
|
|
|
#endif
|
|
|
|
case _SC_V6_ILP32_OFFBIG:
|
|
|
|
#if _V6_ILP32_OFFBIG == 0
|
|
|
|
if (sizeof(int) * CHAR_BIT == 32 &&
|
|
|
|
sizeof(int) == sizeof(long) &&
|
|
|
|
sizeof(long) == sizeof(void *) &&
|
|
|
|
sizeof(off_t) * CHAR_BIT >= 64)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
#else
|
|
|
|
return (_V6_ILP32_OFFBIG);
|
|
|
|
#endif
|
|
|
|
case _SC_V6_LP64_OFF64:
|
|
|
|
#if _V6_LP64_OFF64 == 0
|
|
|
|
if (sizeof(int) * CHAR_BIT == 32 &&
|
|
|
|
sizeof(long) * CHAR_BIT == 64 &&
|
|
|
|
sizeof(long) == sizeof(void *) &&
|
|
|
|
sizeof(void *) == sizeof(off_t))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
#else
|
|
|
|
return (_V6_LP64_OFF64);
|
|
|
|
#endif
|
|
|
|
case _SC_V6_LPBIG_OFFBIG:
|
|
|
|
#if _V6_LPBIG_OFFBIG == 0
|
|
|
|
if (sizeof(int) * CHAR_BIT >= 32 &&
|
|
|
|
sizeof(long) * CHAR_BIT >= 64 &&
|
|
|
|
sizeof(void *) * CHAR_BIT >= 64 &&
|
|
|
|
sizeof(off_t) * CHAR_BIT >= 64)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
#else
|
|
|
|
return (_V6_LPBIG_OFFBIG);
|
|
|
|
#endif
|
|
|
|
case _SC_ATEXIT_MAX:
|
|
|
|
return (ATEXIT_SIZE);
|
2001-06-18 20:24:54 +00:00
|
|
|
case _SC_IOV_MAX:
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_IOV_MAX;
|
|
|
|
break;
|
2002-09-21 02:14:04 +00:00
|
|
|
case _SC_XOPEN_CRYPT:
|
|
|
|
return (_XOPEN_CRYPT);
|
|
|
|
case _SC_XOPEN_ENH_I18N:
|
|
|
|
return (_XOPEN_ENH_I18N);
|
|
|
|
case _SC_XOPEN_LEGACY:
|
|
|
|
return (_XOPEN_LEGACY);
|
|
|
|
case _SC_XOPEN_REALTIME:
|
|
|
|
#if _XOPEN_REALTIME == 0
|
|
|
|
sverrno = errno;
|
|
|
|
value = sysconf(_SC_ASYNCHRONOUS_IO) > 0 &&
|
|
|
|
sysconf(_SC_MEMLOCK) > 0 &&
|
|
|
|
sysconf(_SC_MEMLOCK_RANGE) > 0 &&
|
|
|
|
sysconf(_SC_MESSAGE_PASSING) > 0 &&
|
|
|
|
sysconf(_SC_PRIORITY_SCHEDULING) > 0 &&
|
|
|
|
sysconf(_SC_REALTIME_SIGNALS) > 0 &&
|
|
|
|
sysconf(_SC_SEMAPHORES) > 0 &&
|
|
|
|
sysconf(_SC_SHARED_MEMORY_OBJECTS) > 0 &&
|
|
|
|
sysconf(_SC_SYNCHRONIZED_IO) > 0 &&
|
|
|
|
sysconf(_SC_TIMERS) > 0;
|
|
|
|
errno = sverrno;
|
|
|
|
if (value)
|
|
|
|
return (200112L);
|
|
|
|
else
|
|
|
|
return (-1);
|
|
|
|
#else
|
|
|
|
return (_XOPEN_REALTIME);
|
2001-06-18 20:24:54 +00:00
|
|
|
#endif
|
2002-09-21 02:14:04 +00:00
|
|
|
case _SC_XOPEN_REALTIME_THREADS:
|
|
|
|
#if _XOPEN_REALTIME_THREADS == 0
|
|
|
|
#error "_XOPEN_REALTIME_THREADS"
|
|
|
|
#else
|
|
|
|
return (_XOPEN_REALTIME_THREADS);
|
|
|
|
#endif
|
|
|
|
case _SC_XOPEN_SHM:
|
2007-04-14 13:06:57 +00:00
|
|
|
len = sizeof(lvalue);
|
2002-09-21 02:14:04 +00:00
|
|
|
sverrno = errno;
|
2007-04-14 13:06:57 +00:00
|
|
|
if (sysctlbyname("kern.ipc.shmmin", &lvalue, &len, NULL,
|
2002-09-21 02:14:04 +00:00
|
|
|
0) == -1) {
|
|
|
|
errno = sverrno;
|
1994-05-27 05:00:24 +00:00
|
|
|
return (-1);
|
2002-09-21 02:14:04 +00:00
|
|
|
}
|
|
|
|
errno = sverrno;
|
|
|
|
return (1);
|
|
|
|
case _SC_XOPEN_STREAMS:
|
|
|
|
return (_XOPEN_STREAMS);
|
|
|
|
case _SC_XOPEN_UNIX:
|
|
|
|
return (_XOPEN_UNIX);
|
|
|
|
#ifdef _XOPEN_VERSION
|
|
|
|
case _SC_XOPEN_VERSION:
|
|
|
|
return (_XOPEN_VERSION);
|
|
|
|
#endif
|
|
|
|
#ifdef _XOPEN_XCU_VERSION
|
|
|
|
case _SC_XOPEN_XCU_VERSION:
|
|
|
|
return (_XOPEN_XCU_VERSION);
|
|
|
|
#endif
|
2002-10-27 18:03:02 +00:00
|
|
|
case _SC_SYMLOOP_MAX:
|
|
|
|
return (MAXSYMLINKS);
|
|
|
|
case _SC_RAW_SOCKETS:
|
|
|
|
return (_POSIX_RAW_SOCKETS);
|
|
|
|
case _SC_IPV6:
|
|
|
|
#if _POSIX_IPV6 == 0
|
|
|
|
sverrno = errno;
|
2015-12-20 23:05:20 +00:00
|
|
|
value = _socket(PF_INET6, SOCK_DGRAM, 0);
|
2002-10-27 18:03:02 +00:00
|
|
|
errno = sverrno;
|
|
|
|
if (value >= 0) {
|
2015-12-20 23:05:20 +00:00
|
|
|
_close(value);
|
2002-10-27 18:03:02 +00:00
|
|
|
return (200112L);
|
|
|
|
} else
|
|
|
|
return (0);
|
|
|
|
#else
|
|
|
|
return (_POSIX_IPV6);
|
|
|
|
#endif
|
2002-09-21 02:14:04 +00:00
|
|
|
|
|
|
|
case _SC_NPROCESSORS_CONF:
|
|
|
|
case _SC_NPROCESSORS_ONLN:
|
2012-06-27 20:32:45 +00:00
|
|
|
if (_elf_aux_info(AT_NCPUS, &value, sizeof(value)) == 0)
|
|
|
|
return ((long)value);
|
2002-09-21 02:14:04 +00:00
|
|
|
mib[0] = CTL_HW;
|
|
|
|
mib[1] = HW_NCPU;
|
|
|
|
break;
|
|
|
|
|
2006-12-14 22:14:14 +00:00
|
|
|
#ifdef _SC_PHYS_PAGES
|
2006-12-14 14:32:59 +00:00
|
|
|
case _SC_PHYS_PAGES:
|
2007-04-14 13:06:57 +00:00
|
|
|
len = sizeof(lvalue);
|
|
|
|
if (sysctlbyname("hw.availpages", &lvalue, &len, NULL, 0) == -1)
|
|
|
|
return (-1);
|
|
|
|
return (lvalue);
|
2006-12-14 22:14:14 +00:00
|
|
|
#endif
|
2006-12-14 14:32:59 +00:00
|
|
|
|
2010-10-29 13:31:10 +00:00
|
|
|
#ifdef _SC_CPUSET_SIZE
|
|
|
|
case _SC_CPUSET_SIZE:
|
2011-06-16 02:22:24 +00:00
|
|
|
len = sizeof(value);
|
|
|
|
if (sysctlbyname("kern.sched.cpusetsize", &value, &len, NULL,
|
2010-10-29 13:31:10 +00:00
|
|
|
0) == -1)
|
|
|
|
return (-1);
|
2011-06-16 02:22:24 +00:00
|
|
|
return ((long)value);
|
2010-10-29 13:31:10 +00:00
|
|
|
#endif
|
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
default:
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
2007-04-14 13:06:57 +00:00
|
|
|
len = sizeof(value);
|
|
|
|
if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
|
|
|
|
value = -1;
|
|
|
|
return ((long)value);
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|