blob: c049dc98d50a38cb7b7af16ea9289d3eceb364b0 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* Copyright (C) 1991,1993,1995-1997,2000
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20#define _XOPEN_SOURCE 500
21#include <features.h>
22#include <errno.h>
23#include <limits.h>
24#include <grp.h>
25#include <pwd.h>
26#include <stddef.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <time.h>
30#include <unistd.h>
31#include <sys/syscall.h>
32#include <sys/sysinfo.h>
33#include <sys/types.h>
34#include <sys/param.h>
35#ifdef __UCLIBC_HAS_REGEX__
36#include <regex.h>
37#endif
38#ifdef __UCLIBC_HAS_THREADS_NATIVE__
39#include <sysdep.h>
40#endif
41#include <sys/resource.h>
42#include <string.h>
43#include <dirent.h>
44#include "internal/parse_config.h"
45
46static int nprocessors_onln(void)
47{
48 char **l = NULL;
49 parser_t *p = config_open("/proc/stat");
50 int ret = 0;
51
52 if (p) {
53 while (config_read(p, &l, 2, 1, " ", 0))
54 if (l[0][0] == 'c'
55 && l[0][1] == 'p'
56 && l[0][2] == 'u'
57 && isdigit(l[0][3]))
58 ++ret;
59 } else if ((p = config_open("/proc/cpuinfo"))) {
60#if defined __sparc__
61 while (config_read(p, &l, 2, 2, "\0:", PARSE_NORMAL))
62 if (strncmp("ncpus active", l[0], 12) == 0) {
63 ret = atoi(l[1]);
64 break;
65 }
66#else
67 while (config_read(p, &l, 2, 2, "\0:\t", PARSE_NORMAL))
68 if (strcmp("processor", l[0]) == 0)
69 ++ret;
70#endif
71 }
72 config_close(p);
73 return ret != 0 ? ret : 1;
74}
75
76#if defined __UCLIBC__ && !defined __UCLIBC_HAS_LFS__
77# define readdir64 readdir
78# define dirent64 dirent
79#endif
80static int nprocessors_conf(void)
81{
82 int ret = 0;
83 DIR *dir = opendir("/sys/devices/system/cpu");
84
85 if (dir) {
86 struct dirent64 *dp;
87
88 while ((dp = readdir64(dir))) {
89 if (dp->d_type == DT_DIR
90 && dp->d_name[0] == 'c'
91 && dp->d_name[1] == 'p'
92 && dp->d_name[2] == 'u'
93 && isdigit(dp->d_name[3]))
94 ++ret;
95 }
96 closedir(dir);
97 } else
98 {
99#if defined __sparc__
100 char **l = NULL;
101 parser_t *p = config_open("/proc/stat");
102 while (config_read(p, &l, 2, 2, "\0:", PARSE_NORMAL))
103 if (strncmp("ncpus probed", l[0], 13) == 0) {
104 ret = atoi(l[1]);
105 break;
106 }
107 config_close(p);
108#else
109 ret = nprocessors_onln();
110#endif
111 }
112 return ret != 0 ? ret : 1;
113}
114
115
116#ifndef __UCLIBC_CLK_TCK_CONST
117#error __UCLIBC_CLK_TCK_CONST not defined!
118#endif
119
120/***********************************************************************/
121/*
122 * Manuel Novoa III Jan 2001
123 *
124 * On i386, the switch-based implementation generates 796 bytes of code.
125 * However, many of the return values are repeats. By collecting these
126 * repeats and moving to a table-based implementation, we generate 283
127 * bytes on i386 (-Os -fomit-frame-pointer).
128 */
129
130#ifdef _UCLIBC_GENERATE_SYSCONF_ARCH
131/*
132 * Set some errno's so the auto-gen code knows what it is dealing with.
133 * 1) ENOSYS signifies that we're returning a default value.
134 * This is just extra info for development.
135 * 2) EISNAM signifies that the value returned varies at runtime.
136 *
137 * Option: GETPAGESIZE_IS_DYNAMIC
138 * The current implementation of getpagesize in uClibc returns
139 * a constant. The pagesize on the target arch should not vary,
140 * so it should be safe to set this as 0.
141 */
142#define RETURN_NEG_1 __set_errno(ENOSYS); return -1
143#define RETURN_FUNCTION(f) __set_errno(EISNAM); return (long int) #f
144#define GETPAGESIZE_IS_DYNAMIC 0
145#else
146#define RETURN_NEG_1 return -1
147#define RETURN_FUNCTION(f) return f;
148#endif /* _UCLIBC_GENERATE_SYSCONF_ARCH */
149
150/* Legacy value of ARG_MAX. The macro is now not defined since the
151 actual value varies based on the stack size. */
152#define legacy_ARG_MAX 131072
153
154/* Get the value of the system variable NAME. */
155long int sysconf(int name)
156{
157 struct rlimit rlimit;
158
159 switch (name)
160 {
161 default:
162 __set_errno(EINVAL);
163 return -1;
164
165 case _SC_ARG_MAX:
166 /* Use getrlimit to get the stack limit. */
167 if (getrlimit (RLIMIT_STACK, &rlimit) == 0)
168 return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
169#if defined ARG_MAX
170 return ARG_MAX;
171#else
172 return legacy_ARG_MAX;
173#endif
174
175 case _SC_CHILD_MAX:
176#ifdef CHILD_MAX
177 return CHILD_MAX;
178#else
179 RETURN_NEG_1;
180#endif
181
182 case _SC_CLK_TCK:
183 /* Can't use CLK_TCK here since that calls __sysconf(_SC_CLK_TCK) */
184 return __UCLIBC_CLK_TCK_CONST;
185
186 case _SC_NGROUPS_MAX:
187#ifdef NGROUPS_MAX
188 return NGROUPS_MAX;
189#else
190 RETURN_NEG_1;
191#endif
192
193 case _SC_OPEN_MAX:
194 RETURN_FUNCTION(getdtablesize());
195
196 case _SC_STREAM_MAX:
197#ifdef STREAM_MAX
198 return STREAM_MAX;
199#else
200 return FOPEN_MAX;
201#endif
202
203 case _SC_TZNAME_MAX:
204 return _POSIX_TZNAME_MAX;
205
206 case _SC_JOB_CONTROL:
207#ifdef _POSIX_JOB_CONTROL
208 return 1;
209#else
210 RETURN_NEG_1;
211#endif
212
213 case _SC_SAVED_IDS:
214#ifdef _POSIX_SAVED_IDS
215 return 1;
216#else
217 RETURN_NEG_1;
218#endif
219
220 case _SC_REALTIME_SIGNALS:
221#ifdef _POSIX_REALTIME_SIGNALS
222 return 1;
223#else
224 RETURN_NEG_1;
225#endif
226
227 case _SC_PRIORITY_SCHEDULING:
228#ifdef _POSIX_PRIORITY_SCHEDULING
229 return 1;
230#else
231 RETURN_NEG_1;
232#endif
233
234 case _SC_TIMERS:
235#ifdef _POSIX_TIMERS
236 return 1;
237#else
238 RETURN_NEG_1;
239#endif
240
241 case _SC_ASYNCHRONOUS_IO:
242#ifdef _POSIX_ASYNCHRONOUS_IO
243 return 1;
244#else
245 RETURN_NEG_1;
246#endif
247
248 case _SC_PRIORITIZED_IO:
249#ifdef _POSIX_PRIORITIZED_IO
250 return 1;
251#else
252 RETURN_NEG_1;
253#endif
254
255 case _SC_SYNCHRONIZED_IO:
256#ifdef _POSIX_SYNCHRONIZED_IO
257 return 1;
258#else
259 RETURN_NEG_1;
260#endif
261
262 case _SC_FSYNC:
263#ifdef _POSIX_FSYNC
264 return 1;
265#else
266 RETURN_NEG_1;
267#endif
268
269 case _SC_MAPPED_FILES:
270#ifdef _POSIX_MAPPED_FILES
271 return 1;
272#else
273 RETURN_NEG_1;
274#endif
275
276 case _SC_MEMLOCK:
277#ifdef _POSIX_MEMLOCK
278 return 1;
279#else
280 RETURN_NEG_1;
281#endif
282
283 case _SC_MEMLOCK_RANGE:
284#ifdef _POSIX_MEMLOCK_RANGE
285 return 1;
286#else
287 RETURN_NEG_1;
288#endif
289
290 case _SC_MEMORY_PROTECTION:
291#ifdef _POSIX_MEMORY_PROTECTION
292 return 1;
293#else
294 RETURN_NEG_1;
295#endif
296
297 case _SC_MESSAGE_PASSING:
298#ifdef _POSIX_MESSAGE_PASSING
299 return 1;
300#else
301 RETURN_NEG_1;
302#endif
303
304 case _SC_SEMAPHORES:
305#ifdef _POSIX_SEMAPHORES
306 return 1;
307#else
308 RETURN_NEG_1;
309#endif
310
311 case _SC_SHARED_MEMORY_OBJECTS:
312#ifdef _POSIX_SHARED_MEMORY_OBJECTS
313 return 1;
314#else
315 RETURN_NEG_1;
316#endif
317
318 case _SC_VERSION:
319 return _POSIX_VERSION;
320
321 case _SC_PAGESIZE:
322#if defined(GETPAGESIZE_IS_DYNAMIC) && (GETPAGESIZE_IS_DYNAMIC == 1)
323 RETURN_FUNCTION(getpagesize());
324#else
325 return getpagesize(); /* note: currently this is not dynamic */
326#endif
327
328 case _SC_AIO_LISTIO_MAX:
329#ifdef AIO_LISTIO_MAX
330 return AIO_LISTIO_MAX;
331#else
332 RETURN_NEG_1;
333#endif
334
335 case _SC_AIO_MAX:
336#ifdef AIO_MAX
337 return AIO_MAX;
338#else
339 RETURN_NEG_1;
340#endif
341
342 case _SC_AIO_PRIO_DELTA_MAX:
343#ifdef AIO_PRIO_DELTA_MAX
344 return AIO_PRIO_DELTA_MAX;
345#else
346 RETURN_NEG_1;
347#endif
348
349 case _SC_DELAYTIMER_MAX:
350#ifdef DELAYTIMER_MAX
351 return DELAYTIMER_MAX;
352#else
353 RETURN_NEG_1;
354#endif
355
356 case _SC_MQ_OPEN_MAX:
357#ifdef MQ_OPEN_MAX
358 return MQ_OPEN_MAX;
359#else
360 RETURN_NEG_1;
361#endif
362
363 case _SC_MQ_PRIO_MAX:
364#ifdef MQ_PRIO_MAX
365 return MQ_PRIO_MAX;
366#else
367 RETURN_NEG_1;
368#endif
369
370 case _SC_RTSIG_MAX:
371#ifdef RTSIG_MAX
372 return RTSIG_MAX;
373#else
374 RETURN_NEG_1;
375#endif
376
377 case _SC_SEM_NSEMS_MAX:
378#ifdef SEM_NSEMS_MAX
379 return SEM_NSEMS_MAX;
380#else
381 RETURN_NEG_1;
382#endif
383
384 case _SC_SEM_VALUE_MAX:
385#ifdef SEM_VALUE_MAX
386 return SEM_VALUE_MAX;
387#else
388 RETURN_NEG_1;
389#endif
390
391 case _SC_SIGQUEUE_MAX:
392#ifdef SIGQUEUE_MAX
393 return SIGQUEUE_MAX;
394#else
395 RETURN_NEG_1;
396#endif
397
398 case _SC_TIMER_MAX:
399#ifdef TIMER_MAX
400 return TIMER_MAX;
401#else
402 RETURN_NEG_1;
403#endif
404
405 case _SC_BC_BASE_MAX:
406#ifdef BC_BASE_MAX
407 return BC_BASE_MAX;
408#else
409 RETURN_NEG_1;
410#endif
411
412 case _SC_BC_DIM_MAX:
413#ifdef BC_DIM_MAX
414 return BC_DIM_MAX;
415#else
416 RETURN_NEG_1;
417#endif
418
419 case _SC_BC_SCALE_MAX:
420#ifdef BC_SCALE_MAX
421 return BC_SCALE_MAX;
422#else
423 RETURN_NEG_1;
424#endif
425
426 case _SC_BC_STRING_MAX:
427#ifdef BC_STRING_MAX
428 return BC_STRING_MAX;
429#else
430 RETURN_NEG_1;
431#endif
432
433 case _SC_COLL_WEIGHTS_MAX:
434#ifdef COLL_WEIGHTS_MAX
435 return COLL_WEIGHTS_MAX;
436#else
437 RETURN_NEG_1;
438#endif
439
440 case _SC_EQUIV_CLASS_MAX:
441#ifdef EQUIV_CLASS_MAX
442 return EQUIV_CLASS_MAX;
443#else
444 RETURN_NEG_1;
445#endif
446
447 case _SC_EXPR_NEST_MAX:
448#ifdef EXPR_NEST_MAX
449 return EXPR_NEST_MAX;
450#else
451 RETURN_NEG_1;
452#endif
453
454 case _SC_LINE_MAX:
455#ifdef LINE_MAX
456 return LINE_MAX;
457#else
458 RETURN_NEG_1;
459#endif
460
461 case _SC_RE_DUP_MAX:
462#ifdef RE_DUP_MAX
463 return RE_DUP_MAX;
464#else
465 RETURN_NEG_1;
466#endif
467
468 case _SC_CHARCLASS_NAME_MAX:
469#ifdef CHARCLASS_NAME_MAX
470 return CHARCLASS_NAME_MAX;
471#else
472 RETURN_NEG_1;
473#endif
474
475 case _SC_PII:
476#ifdef _POSIX_PII
477 return 1;
478#else
479 RETURN_NEG_1;
480#endif
481
482 case _SC_PII_XTI:
483#ifdef _POSIX_PII_XTI
484 return 1;
485#else
486 RETURN_NEG_1;
487#endif
488
489 case _SC_PII_SOCKET:
490#ifdef _POSIX_PII_SOCKET
491 return 1;
492#else
493 RETURN_NEG_1;
494#endif
495
496 case _SC_PII_INTERNET:
497#ifdef _POSIX_PII_INTERNET
498 return 1;
499#else
500 RETURN_NEG_1;
501#endif
502
503 case _SC_PII_OSI:
504#ifdef _POSIX_PII_OSI
505 return 1;
506#else
507 RETURN_NEG_1;
508#endif
509
510 case _SC_POLL:
511#ifdef _POSIX_POLL
512 return 1;
513#else
514 RETURN_NEG_1;
515#endif
516
517 case _SC_SELECT:
518#ifdef _POSIX_SELECT
519 return 1;
520#else
521 RETURN_NEG_1;
522#endif
523
524 case _SC_UIO_MAXIOV:
525#ifdef UIO_MAXIOV
526 return UIO_MAXIOV;
527#else
528 RETURN_NEG_1;
529#endif
530
531 case _SC_PII_INTERNET_STREAM:
532#ifdef _POSIX_PII_INTERNET_STREAM
533 return 1;
534#else
535 RETURN_NEG_1;
536#endif
537
538 case _SC_PII_INTERNET_DGRAM:
539#ifdef _POSIX_PII_INTERNET_DGRAM
540 return 1;
541#else
542 RETURN_NEG_1;
543#endif
544
545 case _SC_PII_OSI_COTS:
546#ifdef _POSIX_PII_OSI_COTS
547 return 1;
548#else
549 RETURN_NEG_1;
550#endif
551
552 case _SC_PII_OSI_CLTS:
553#ifdef _POSIX_PII_OSI_CLTS
554 return 1;
555#else
556 RETURN_NEG_1;
557#endif
558
559 case _SC_PII_OSI_M:
560#ifdef _POSIX_PII_OSI_M
561 return 1;
562#else
563 RETURN_NEG_1;
564#endif
565
566 case _SC_T_IOV_MAX:
567#ifdef _T_IOV_MAX
568 return _T_IOV_MAX;
569#else
570 RETURN_NEG_1;
571#endif
572
573 case _SC_2_VERSION:
574 return _POSIX2_VERSION;
575
576 case _SC_2_C_BIND:
577#ifdef _POSIX2_C_BIND
578 return _POSIX2_C_BIND;
579#else
580 RETURN_NEG_1;
581#endif
582
583 case _SC_2_C_DEV:
584#ifdef _POSIX2_C_DEV
585 return _POSIX2_C_DEV;
586#else
587 RETURN_NEG_1;
588#endif
589
590 case _SC_2_C_VERSION:
591#ifdef _POSIX2_C_VERSION
592 return _POSIX2_C_VERSION;
593#else
594 RETURN_NEG_1;
595#endif
596
597 case _SC_2_FORT_DEV:
598#ifdef _POSIX2_FORT_DEV
599 return _POSIX2_FORT_DEV;
600#else
601 RETURN_NEG_1;
602#endif
603
604 case _SC_2_FORT_RUN:
605#ifdef _POSIX2_FORT_RUN
606 return _POSIX2_FORT_RUN;
607#else
608 RETURN_NEG_1;
609#endif
610
611 case _SC_2_LOCALEDEF:
612#ifdef _POSIX2_LOCALEDEF
613 return _POSIX2_LOCALEDEF;
614#else
615 RETURN_NEG_1;
616#endif
617
618 case _SC_2_SW_DEV:
619#ifdef _POSIX2_SW_DEV
620 return _POSIX2_SW_DEV;
621#else
622 RETURN_NEG_1;
623#endif
624
625 case _SC_2_CHAR_TERM:
626#ifdef _POSIX2_CHAR_TERM
627 return _POSIX2_CHAR_TERM;
628#else
629 RETURN_NEG_1;
630#endif
631
632 case _SC_2_UPE:
633#ifdef _POSIX2_UPE
634 return _POSIX2_UPE;
635#else
636 RETURN_NEG_1;
637#endif
638
639 /* POSIX 1003.1c (POSIX Threads). */
640 case _SC_THREADS:
641#ifdef __UCLIBC_HAS_THREADS__
642 return 1;
643#else
644 RETURN_NEG_1;
645#endif
646
647 case _SC_THREAD_SAFE_FUNCTIONS:
648#ifdef __UCLIBC_HAS_THREADS__
649 return 1;
650#else
651 RETURN_NEG_1;
652#endif
653
654/* If you change these, also change libc/pwd_grp/pwd_grp.c to match */
655 case _SC_GETGR_R_SIZE_MAX:
656 return __UCLIBC_GRP_BUFFER_SIZE__;
657
658 case _SC_GETPW_R_SIZE_MAX:
659 return __UCLIBC_PWD_BUFFER_SIZE__;
660
661/* getlogin() is a worthless interface. In uClibc we let the user specify
662 * whatever they want via the LOGNAME environment variable, or we return NULL
663 * if getenv() fails to find anything. So this is merely how large a env
664 * variable can be. Lets use 256 */
665 case _SC_LOGIN_NAME_MAX:
666 return 256;
667
668/* If you change this, also change _SC_TTY_NAME_MAX in libc/unistd/sysconf.c */
669#define TTYNAME_BUFLEN 32
670 case _SC_TTY_NAME_MAX:
671 return TTYNAME_BUFLEN;
672
673 case _SC_THREAD_DESTRUCTOR_ITERATIONS:
674#ifdef _POSIX_THREAD_DESTRUCTOR_ITERATIONS
675 return _POSIX_THREAD_DESTRUCTOR_ITERATIONS;
676#else
677 RETURN_NEG_1;
678#endif
679
680 case _SC_THREAD_KEYS_MAX:
681#ifdef PTHREAD_KEYS_MAX
682 return PTHREAD_KEYS_MAX;
683#else
684 RETURN_NEG_1;
685#endif
686
687 case _SC_THREAD_STACK_MIN:
688#ifdef PTHREAD_STACK_MIN
689 return PTHREAD_STACK_MIN;
690#else
691 RETURN_NEG_1;
692#endif
693
694 case _SC_THREAD_THREADS_MAX:
695#ifdef PTHREAD_THREADS_MAX
696 return PTHREAD_THREADS_MAX;
697#else
698 RETURN_NEG_1;
699#endif
700
701 case _SC_THREAD_ATTR_STACKADDR:
702#ifdef _POSIX_THREAD_ATTR_STACKADDR
703 return 1;
704#else
705 RETURN_NEG_1;
706#endif
707
708 case _SC_THREAD_ATTR_STACKSIZE:
709#ifdef _POSIX_THREAD_ATTR_STACKSIZE
710 return 1;
711#else
712 RETURN_NEG_1;
713#endif
714
715 case _SC_THREAD_PRIORITY_SCHEDULING:
716#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
717 return 1;
718#else
719 RETURN_NEG_1;
720#endif
721
722 case _SC_THREAD_PRIO_INHERIT:
723#ifdef _POSIX_THREAD_PRIO_INHERIT
724 return 1;
725#else
726 RETURN_NEG_1;
727#endif
728
729 case _SC_THREAD_PRIO_PROTECT:
730#ifdef _POSIX_THREAD_PRIO_PROTECT
731 return 1;
732#else
733 RETURN_NEG_1;
734#endif
735
736 case _SC_THREAD_PROCESS_SHARED:
737#ifdef _POSIX_THREAD_PROCESS_SHARED
738 return 1;
739#else
740 RETURN_NEG_1;
741#endif
742
743 case _SC_NPROCESSORS_CONF:
744 RETURN_FUNCTION(nprocessors_conf());
745
746 case _SC_NPROCESSORS_ONLN:
747 RETURN_FUNCTION(nprocessors_onln());
748
749 case _SC_PHYS_PAGES:
750#if 0
751 RETURN_FUNCTION(get_phys_pages());
752#else
753 RETURN_NEG_1;
754#endif
755
756 case _SC_AVPHYS_PAGES:
757#if 0
758 RETURN_FUNCTION(get_avphys_pages());
759#else
760 RETURN_NEG_1;
761#endif
762
763 case _SC_ATEXIT_MAX:
764 return __UCLIBC_MAX_ATEXIT;
765
766 case _SC_PASS_MAX:
767 /* We have no limit but since the return value might be used to
768 allocate a buffer we restrict the value. */
769 return BUFSIZ;
770
771 case _SC_XOPEN_VERSION:
772 return _XOPEN_VERSION;
773
774 case _SC_XOPEN_XCU_VERSION:
775 return _XOPEN_XCU_VERSION;
776
777 case _SC_XOPEN_UNIX:
778 return _XOPEN_UNIX;
779
780 case _SC_XOPEN_CRYPT:
781#ifdef _XOPEN_CRYPT
782 return _XOPEN_CRYPT;
783#else
784 RETURN_NEG_1;
785#endif
786
787 case _SC_XOPEN_ENH_I18N:
788#ifdef _XOPEN_ENH_I18N
789 return _XOPEN_ENH_I18N;
790#else
791 RETURN_NEG_1;
792#endif
793
794 case _SC_XOPEN_SHM:
795#ifdef _XOPEN_SHM
796 return _XOPEN_SHM;
797#else
798 RETURN_NEG_1;
799#endif
800
801 case _SC_XOPEN_XPG2:
802#ifdef _XOPEN_XPG2
803 return _XOPEN_XPG2;
804#else
805 RETURN_NEG_1;
806#endif
807
808 case _SC_XOPEN_XPG3:
809#ifdef _XOPEN_XPG3
810 return _XOPEN_XPG3;
811#else
812 RETURN_NEG_1;
813#endif
814
815 case _SC_XOPEN_XPG4:
816#ifdef _XOPEN_XPG4
817 return _XOPEN_XPG4;
818#else
819 RETURN_NEG_1;
820#endif
821
822 case _SC_CHAR_BIT:
823 return CHAR_BIT;
824
825 case _SC_CHAR_MAX:
826 return CHAR_MAX;
827
828 case _SC_CHAR_MIN:
829 return CHAR_MIN;
830
831 case _SC_INT_MAX:
832 return INT_MAX;
833
834 case _SC_INT_MIN:
835 return INT_MIN;
836
837 case _SC_LONG_BIT:
838 return sizeof (long int) * CHAR_BIT;
839
840 case _SC_WORD_BIT:
841 return sizeof (int) * CHAR_BIT;
842
843 case _SC_MB_LEN_MAX:
844 return MB_LEN_MAX;
845
846 case _SC_NZERO:
847 return NZERO;
848
849 case _SC_SSIZE_MAX:
850 return _POSIX_SSIZE_MAX;
851
852 case _SC_SCHAR_MAX:
853 return SCHAR_MAX;
854
855 case _SC_SCHAR_MIN:
856 return SCHAR_MIN;
857
858 case _SC_SHRT_MAX:
859 return SHRT_MAX;
860
861 case _SC_SHRT_MIN:
862 return SHRT_MIN;
863
864 case _SC_UCHAR_MAX:
865 return UCHAR_MAX;
866
867 case _SC_UINT_MAX:
868 return UINT_MAX;
869
870 case _SC_ULONG_MAX:
871 return ULONG_MAX;
872
873 case _SC_USHRT_MAX:
874 return USHRT_MAX;
875
876 case _SC_NL_ARGMAX:
877#ifdef NL_ARGMAX
878 return NL_ARGMAX;
879#else
880 RETURN_NEG_1;
881#endif
882
883 case _SC_NL_LANGMAX:
884#ifdef NL_LANGMAX
885 return NL_LANGMAX;
886#else
887 RETURN_NEG_1;
888#endif
889
890 case _SC_NL_MSGMAX:
891#ifdef NL_MSGMAX
892 return NL_MSGMAX;
893#else
894 RETURN_NEG_1;
895#endif
896
897 case _SC_NL_NMAX:
898#ifdef NL_NMAX
899 return NL_NMAX;
900#else
901 RETURN_NEG_1;
902#endif
903
904 case _SC_NL_SETMAX:
905#ifdef NL_SETMAX
906 return NL_SETMAX;
907#else
908 RETURN_NEG_1;
909#endif
910
911 case _SC_NL_TEXTMAX:
912#ifdef NL_TEXTMAX
913 return NL_TEXTMAX;
914#else
915 RETURN_NEG_1;
916#endif
917
918 case _SC_XBS5_ILP32_OFF32:
919#ifdef _XBS5_ILP32_OFF32
920 return _XBS5_ILP32_OFF32;
921#else
922 RETURN_NEG_1;
923#endif
924 case _SC_XBS5_ILP32_OFFBIG:
925#ifdef _XBS5_ILP32_OFFBIG
926 return _XBS5_ILP32_OFFBIG;
927#else
928 RETURN_NEG_1;
929#endif
930 case _SC_XBS5_LP64_OFF64:
931#ifdef _XBS5_LP64_OFF64
932 return _XBS5_LP64_OFF64;
933#else
934 RETURN_NEG_1;
935#endif
936 case _SC_XBS5_LPBIG_OFFBIG:
937#ifdef _XBS5_LPBIG_OFFBIG
938 return _XBS5_LPBIG_OFFBIG;
939#else
940 RETURN_NEG_1;
941#endif
942 case _SC_V7_ILP32_OFF32:
943#ifdef _POSIX_V7_ILP32_OFF32
944 return _POSIX_V7_ILP32_OFF32;
945#else
946 RETURN_NEG_1;
947#endif
948 case _SC_V7_ILP32_OFFBIG:
949#ifdef _POSIX_V7_ILP32_OFFBIG
950 return _POSIX_V7_ILP32_OFFBIG;
951#else
952 RETURN_NEG_1;
953#endif
954 case _SC_V7_LP64_OFF64:
955#ifdef _POSIX_V7_LP64_OFF64
956 return _POSIX_V7_LP64_OFF64;
957#else
958 RETURN_NEG_1;
959#endif
960 case _SC_V7_LPBIG_OFFBIG:
961#ifdef _POSIX_V7_LPBIG_OFFBIG
962 return _POSIX_V7_LPBIG_OFFBIG;
963#else
964 RETURN_NEG_1;
965#endif
966
967 case _SC_XOPEN_LEGACY:
968 return _XOPEN_LEGACY;
969
970 case _SC_XOPEN_REALTIME:
971#ifdef _XOPEN_REALTIME
972 return _XOPEN_REALTIME;
973#else
974 RETURN_NEG_1;
975#endif
976 case _SC_XOPEN_REALTIME_THREADS:
977#ifdef _XOPEN_REALTIME_THREADS
978 return _XOPEN_REALTIME_THREADS;
979#else
980 RETURN_NEG_1;
981#endif
982
983 case _SC_MONOTONIC_CLOCK:
984#ifdef __NR_clock_getres
985 /* Check using the clock_getres system call. */
986# ifdef __UCLIBC_HAS_THREADS_NATIVE__
987 {
988 struct timespec ts;
989 INTERNAL_SYSCALL_DECL (err);
990 int r;
991 r = INTERNAL_SYSCALL (clock_getres, err, 2, CLOCK_MONOTONIC, &ts);
992 return INTERNAL_SYSCALL_ERROR_P (r, err) ? -1 : _POSIX_VERSION;
993 }
994# elif defined __UCLIBC_HAS_REALTIME__
995 if (clock_getres(CLOCK_MONOTONIC, NULL) >= 0)
996 return _POSIX_VERSION;
997# endif
998#endif
999 RETURN_NEG_1;
1000
1001#ifdef __UCLIBC_HAS_THREADS_NATIVE__
1002 case _SC_THREAD_CPUTIME:
1003# if _POSIX_THREAD_CPUTIME > 0
1004 return _POSIX_THREAD_CPUTIME;
1005# else
1006 RETURN_NEG_1;
1007# endif
1008#endif
1009 }
1010}
1011libc_hidden_def(sysconf)