1 /* Copyright (C) 1991-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18 #include <errno.h>
19 #include <limits.h>
20 #include <grp.h>
21 #include <pwd.h>
22 #include <stddef.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <time.h>
27 #include <unistd.h>
28 #include <sys/param.h>
29 #include <sys/stat.h>
30 #include <sys/sysinfo.h>
31 #include <sys/types.h>
32 #include <sys/uio.h>
33 #include <regex.h>
34 #include <signal.h>
35 #include <sysconf-pthread_stack_min.h>
36
37 #define NEED_SPEC_ARRAY 0
38 #include <posix-conf-vars.h>
39
40 #define NEED_CHECK_SPEC \
41 (!defined _XBS5_ILP32_OFF32 || !defined _XBS5_ILP32_OFFBIG \
42 || !defined _XBS5_LP64_OFF64 || !defined _XBS5_LPBIG_OFFBIG \
43 || !defined _POSIX_V6_ILP32_OFF32 || !defined _POSIX_V6_ILP32_OFFBIG \
44 || !defined _POSIX_V6_LP64_OFF64 || !defined _POSIX_V6_LPBIG_OFFBIG \
45 || !defined _POSIX_V7_ILP32_OFF32 || !defined _POSIX_V7_ILP32_OFFBIG \
46 || !defined _POSIX_V7_LP64_OFF64 || !defined _POSIX_V7_LPBIG_OFFBIG)
47 #if NEED_CHECK_SPEC
48 static long int __sysconf_check_spec (const char *spec);
49 #endif
50
51
52 /* Get the value of the system variable NAME. */
53 long int
__sysconf(int name)54 __sysconf (int name)
55 {
56 switch (name)
57 {
58 /* Also add obsolete or unnecessarily added constants here. */
59 case _SC_EQUIV_CLASS_MAX:
60 default:
61 __set_errno (EINVAL);
62 return -1;
63
64 case _SC_ARG_MAX:
65 #ifdef ARG_MAX
66 return ARG_MAX;
67 #else
68 return -1;
69 #endif
70
71 case _SC_CHILD_MAX:
72 #ifdef CHILD_MAX
73 return CHILD_MAX;
74 #else
75 return __get_child_max ();
76 #endif
77
78 case _SC_CLK_TCK:
79 return __getclktck ();
80
81 case _SC_NGROUPS_MAX:
82 #ifdef NGROUPS_MAX
83 return NGROUPS_MAX;
84 #else
85 return -1;
86 #endif
87
88 case _SC_OPEN_MAX:
89 return __getdtablesize ();
90
91 case _SC_STREAM_MAX:
92 #ifdef STREAM_MAX
93 return STREAM_MAX;
94 #else
95 return FOPEN_MAX;
96 #endif
97
98 case _SC_TZNAME_MAX:
99 return -1;
100
101 case _SC_JOB_CONTROL:
102 #if CONF_IS_DEFINED_SET (_POSIX_JOB_CONTROL)
103 return _POSIX_JOB_CONTROL;
104 #else
105 return -1;
106 #endif
107
108 case _SC_SAVED_IDS:
109 #if CONF_IS_DEFINED_SET (_POSIX_SAVED_IDS)
110 return 1;
111 #else
112 return -1;
113 #endif
114
115 case _SC_REALTIME_SIGNALS:
116 #if CONF_IS_DEFINED_SET (_POSIX_REALTIME_SIGNALS)
117 return _POSIX_REALTIME_SIGNALS;
118 #else
119 return -1;
120 #endif
121
122 case _SC_PRIORITY_SCHEDULING:
123 #if CONF_IS_DEFINED_SET (_POSIX_PRIORITY_SCHEDULING)
124 return _POSIX_PRIORITY_SCHEDULING;
125 #else
126 return -1;
127 #endif
128
129 case _SC_TIMERS:
130 #if CONF_IS_DEFINED_SET (_POSIX_TIMERS)
131 return _POSIX_TIMERS;
132 #else
133 return -1;
134 #endif
135
136 case _SC_ASYNCHRONOUS_IO:
137 #if CONF_IS_DEFINED_SET (_POSIX_ASYNCHRONOUS_IO)
138 return _POSIX_ASYNCHRONOUS_IO;
139 #else
140 return -1;
141 #endif
142
143 case _SC_PRIORITIZED_IO:
144 #if CONF_IS_DEFINED_SET (_POSIX_PRIORITIZED_IO)
145 return _POSIX_PRIORITIZED_IO;
146 #else
147 return -1;
148 #endif
149
150 case _SC_SYNCHRONIZED_IO:
151 #if CONF_IS_DEFINED_SET (_POSIX_SYNCHRONIZED_IO)
152 return _POSIX_SYNCHRONIZED_IO;
153 #else
154 return -1;
155 #endif
156
157 case _SC_FSYNC:
158 #if CONF_IS_DEFINED_SET (_POSIX_FSYNC)
159 return _POSIX_FSYNC;
160 #else
161 return -1;
162 #endif
163
164 case _SC_MAPPED_FILES:
165 #if CONF_IS_DEFINED_SET (_POSIX_MAPPED_FILES)
166 return _POSIX_MAPPED_FILES;
167 #else
168 return -1;
169 #endif
170
171 case _SC_MEMLOCK:
172 #if CONF_IS_DEFINED_SET (_POSIX_MEMLOCK)
173 return _POSIX_MEMLOCK;
174 #else
175 return -1;
176 #endif
177
178 case _SC_MEMLOCK_RANGE:
179 #if CONF_IS_DEFINED_SET (_POSIX_MEMLOCK_RANGE)
180 return _POSIX_MEMLOCK_RANGE;
181 #else
182 return -1;
183 #endif
184
185 case _SC_MEMORY_PROTECTION:
186 #if CONF_IS_DEFINED_SET (_POSIX_MEMORY_PROTECTION)
187 return _POSIX_MEMORY_PROTECTION;
188 #else
189 return -1;
190 #endif
191
192 case _SC_MESSAGE_PASSING:
193 #if CONF_IS_DEFINED_SET (_POSIX_MESSAGE_PASSING)
194 return _POSIX_MESSAGE_PASSING;
195 #else
196 return -1;
197 #endif
198
199 case _SC_SEMAPHORES:
200 #if CONF_IS_DEFINED_SET (_POSIX_SEMAPHORES)
201 return _POSIX_SEMAPHORES;
202 #else
203 return -1;
204 #endif
205
206 case _SC_SHARED_MEMORY_OBJECTS:
207 #if CONF_IS_DEFINED_SET (_POSIX_SHARED_MEMORY_OBJECTS)
208 return _POSIX_SHARED_MEMORY_OBJECTS;
209 #else
210 return -1;
211 #endif
212
213 case _SC_VERSION:
214 return _POSIX_VERSION;
215
216 case _SC_PAGESIZE:
217 return __getpagesize ();
218
219 case _SC_AIO_LISTIO_MAX:
220 #ifdef AIO_LISTIO_MAX
221 return AIO_LISTIO_MAX;
222 #else
223 return -1;
224 #endif
225
226 case _SC_AIO_MAX:
227 #ifdef AIO_MAX
228 return AIO_MAX;
229 #else
230 return -1;
231 #endif
232
233 case _SC_AIO_PRIO_DELTA_MAX:
234 #ifdef AIO_PRIO_DELTA_MAX
235 return AIO_PRIO_DELTA_MAX;
236 #else
237 return -1;
238 #endif
239
240 case _SC_DELAYTIMER_MAX:
241 #ifdef DELAYTIMER_MAX
242 return DELAYTIMER_MAX;
243 #else
244 return -1;
245 #endif
246
247 case _SC_MQ_OPEN_MAX:
248 #ifdef MQ_OPEN_MAX
249 return MQ_OPEN_MAX;
250 #else
251 return -1;
252 #endif
253
254 case _SC_MQ_PRIO_MAX:
255 #ifdef MQ_PRIO_MAX
256 return MQ_PRIO_MAX;
257 #else
258 return -1;
259 #endif
260
261 case _SC_RTSIG_MAX:
262 #ifdef RTSIG_MAX
263 return RTSIG_MAX;
264 #else
265 return -1;
266 #endif
267
268 case _SC_SEM_NSEMS_MAX:
269 #ifdef SEM_NSEMS_MAX
270 return SEM_NSEMS_MAX;
271 #else
272 return -1;
273 #endif
274
275 case _SC_SEM_VALUE_MAX:
276 #ifdef SEM_VALUE_MAX
277 return SEM_VALUE_MAX;
278 #else
279 return -1;
280 #endif
281
282 case _SC_SIGQUEUE_MAX:
283 #ifdef SIGQUEUE_MAX
284 return SIGQUEUE_MAX;
285 #else
286 return -1;
287 #endif
288
289 case _SC_TIMER_MAX:
290 #ifdef TIMER_MAX
291 return TIMER_MAX;
292 #else
293 return -1;
294 #endif
295
296 case _SC_BC_BASE_MAX:
297 #ifdef BC_BASE_MAX
298 return BC_BASE_MAX;
299 #else
300 return -1;
301 #endif
302
303 case _SC_BC_DIM_MAX:
304 #ifdef BC_DIM_MAX
305 return BC_DIM_MAX;
306 #else
307 return -1;
308 #endif
309
310 case _SC_BC_SCALE_MAX:
311 #ifdef BC_SCALE_MAX
312 return BC_SCALE_MAX;
313 #else
314 return -1;
315 #endif
316
317 case _SC_BC_STRING_MAX:
318 #ifdef BC_STRING_MAX
319 return BC_STRING_MAX;
320 #else
321 return -1;
322 #endif
323
324 case _SC_COLL_WEIGHTS_MAX:
325 #ifdef COLL_WEIGHTS_MAX
326 return COLL_WEIGHTS_MAX;
327 #else
328 return -1;
329 #endif
330
331 case _SC_EXPR_NEST_MAX:
332 #ifdef EXPR_NEST_MAX
333 return EXPR_NEST_MAX;
334 #else
335 return -1;
336 #endif
337
338 case _SC_LINE_MAX:
339 #ifdef LINE_MAX
340 return LINE_MAX;
341 #else
342 return -1;
343 #endif
344
345 case _SC_RE_DUP_MAX:
346 #ifdef RE_DUP_MAX
347 return RE_DUP_MAX;
348 #else
349 return -1;
350 #endif
351
352 case _SC_CHARCLASS_NAME_MAX:
353 #ifdef CHARCLASS_NAME_MAX
354 return CHARCLASS_NAME_MAX;
355 #else
356 return -1;
357 #endif
358
359 case _SC_PII:
360 #if CONF_IS_DEFINED_SET (_POSIX_PII)
361 return 1;
362 #else
363 return -1;
364 #endif
365
366 case _SC_PII_XTI:
367 #if CONF_IS_DEFINED_SET (_POSIX_PII_XTI)
368 return 1;
369 #else
370 return -1;
371 #endif
372
373 case _SC_PII_SOCKET:
374 #if CONF_IS_DEFINED_SET (_POSIX_PII_SOCKET)
375 return 1;
376 #else
377 return -1;
378 #endif
379
380 case _SC_PII_INTERNET:
381 #if CONF_IS_DEFINED_SET (_POSIX_PII_INTERNET)
382 return 1;
383 #else
384 return -1;
385 #endif
386
387 case _SC_PII_OSI:
388 #if CONF_IS_DEFINED_SET (_POSIX_PII_OSI)
389 return 1;
390 #else
391 return -1;
392 #endif
393
394 case _SC_POLL:
395 #if CONF_IS_DEFINED_SET (_POSIX_POLL)
396 return 1;
397 #else
398 return -1;
399 #endif
400
401 case _SC_SELECT:
402 #if CONF_IS_DEFINED_SET (_POSIX_SELECT)
403 return 1;
404 #else
405 return -1;
406 #endif
407
408 /* The same as _SC_IOV_MAX. */
409 case _SC_UIO_MAXIOV:
410 #ifdef UIO_MAXIOV
411 return UIO_MAXIOV;
412 #else
413 return -1;
414 #endif
415
416 case _SC_PII_INTERNET_STREAM:
417 #if CONF_IS_DEFINED_SET (_POSIX_PII_INTERNET_STREAM)
418 return 1;
419 #else
420 return -1;
421 #endif
422
423 case _SC_PII_INTERNET_DGRAM:
424 #if CONF_IS_DEFINED_SET (_POSIX_PII_INTERNET_DGRAM)
425 return 1;
426 #else
427 return -1;
428 #endif
429
430 case _SC_PII_OSI_COTS:
431 #if CONF_IS_DEFINED_SET (_POSIX_PII_OSI_COTS)
432 return 1;
433 #else
434 return -1;
435 #endif
436
437 case _SC_PII_OSI_CLTS:
438 #if CONF_IS_DEFINED_SET (_POSIX_PII_OSI_CLTS)
439 return 1;
440 #else
441 return -1;
442 #endif
443
444 case _SC_PII_OSI_M:
445 #if CONF_IS_DEFINED_SET (_POSIX_PII_OSI_M)
446 return 1;
447 #else
448 return -1;
449 #endif
450
451 case _SC_T_IOV_MAX:
452 #ifdef _T_IOV_MAX
453 return _T_IOV_MAX;
454 #else
455 return -1;
456 #endif
457
458 case _SC_2_VERSION:
459 return _POSIX2_VERSION;
460
461 case _SC_2_C_BIND:
462 #ifdef _POSIX2_C_BIND
463 return _POSIX2_C_BIND;
464 #else
465 return -1;
466 #endif
467
468 case _SC_2_C_DEV:
469 #ifdef _POSIX2_C_DEV
470 return _POSIX2_C_DEV;
471 #else
472 return -1;
473 #endif
474
475 case _SC_2_C_VERSION:
476 #ifdef _POSIX2_C_VERSION
477 return _POSIX2_C_VERSION;
478 #else
479 return -1;
480 #endif
481
482 case _SC_2_FORT_DEV:
483 #ifdef _POSIX2_FORT_DEV
484 return _POSIX2_FORT_DEV;
485 #else
486 return -1;
487 #endif
488
489 case _SC_2_FORT_RUN:
490 #ifdef _POSIX2_FORT_RUN
491 return _POSIX2_FORT_RUN;
492 #else
493 return -1;
494 #endif
495
496 case _SC_2_LOCALEDEF:
497 #ifdef _POSIX2_LOCALEDEF
498 return _POSIX2_LOCALEDEF;
499 #else
500 return -1;
501 #endif
502
503 case _SC_2_SW_DEV:
504 #ifdef _POSIX2_SW_DEV
505 return _POSIX2_SW_DEV;
506 #else
507 return -1;
508 #endif
509
510 case _SC_2_CHAR_TERM:
511 #ifdef _POSIX2_CHAR_TERM
512 return _POSIX2_CHAR_TERM;
513 #else
514 return -1;
515 #endif
516
517 case _SC_2_UPE:
518 #ifdef _POSIX2_UPE
519 return _POSIX2_UPE;
520 #else
521 return -1;
522 #endif
523
524 /* POSIX 1003.1c (POSIX Threads). */
525 case _SC_THREADS:
526 #if CONF_IS_DEFINED_SET (_POSIX_THREADS)
527 return _POSIX_THREADS;
528 #else
529 return -1;
530 #endif
531
532 case _SC_THREAD_SAFE_FUNCTIONS:
533 #if CONF_IS_DEFINED_SET (_POSIX_THREAD_SAFE_FUNCTIONS)
534 return _POSIX_THREAD_SAFE_FUNCTIONS;
535 #else
536 return -1;
537 #endif
538
539 case _SC_GETGR_R_SIZE_MAX:
540 return NSS_BUFLEN_GROUP;
541
542 case _SC_GETPW_R_SIZE_MAX:
543 return NSS_BUFLEN_PASSWD;
544
545 case _SC_LOGIN_NAME_MAX:
546 #ifdef LOGIN_NAME_MAX
547 return LOGIN_NAME_MAX;
548 #else
549 return -1;
550 #endif
551
552 case _SC_TTY_NAME_MAX:
553 #ifdef TTY_NAME_MAX
554 return TTY_NAME_MAX;
555 #else
556 return -1;
557 #endif
558
559 case _SC_THREAD_DESTRUCTOR_ITERATIONS:
560 #if CONF_IS_DEFINED_SET (_POSIX_THREAD_DESTRUCTOR_ITERATIONS)
561 return _POSIX_THREAD_DESTRUCTOR_ITERATIONS;
562 #else
563 return -1;
564 #endif
565
566 case _SC_THREAD_KEYS_MAX:
567 #ifdef PTHREAD_KEYS_MAX
568 return PTHREAD_KEYS_MAX;
569 #else
570 return -1;
571 #endif
572
573 case _SC_THREAD_STACK_MIN:
574 return __get_pthread_stack_min ();
575
576 case _SC_THREAD_THREADS_MAX:
577 #ifdef PTHREAD_THREADS_MAX
578 return PTHREAD_THREADS_MAX;
579 #else
580 return -1;
581 #endif
582
583 case _SC_THREAD_ATTR_STACKADDR:
584 #if CONF_IS_DEFINED_SET (_POSIX_THREAD_ATTR_STACKADDR)
585 return _POSIX_THREAD_ATTR_STACKADDR;
586 #else
587 return -1;
588 #endif
589
590 case _SC_THREAD_ATTR_STACKSIZE:
591 #if CONF_IS_DEFINED_SET (_POSIX_THREAD_ATTR_STACKSIZE)
592 return _POSIX_THREAD_ATTR_STACKSIZE;
593 #else
594 return -1;
595 #endif
596
597 case _SC_THREAD_PRIORITY_SCHEDULING:
598 #if CONF_IS_DEFINED_SET (_POSIX_THREAD_PRIORITY_SCHEDULING)
599 return _POSIX_THREAD_PRIORITY_SCHEDULING;
600 #else
601 return -1;
602 #endif
603
604 case _SC_THREAD_PRIO_INHERIT:
605 #if CONF_IS_DEFINED_SET (_POSIX_THREAD_PRIO_INHERIT)
606 return _POSIX_THREAD_PRIO_INHERIT;
607 #else
608 return -1;
609 #endif
610
611 case _SC_THREAD_PRIO_PROTECT:
612 #if CONF_IS_DEFINED_SET (_POSIX_THREAD_PRIO_PROTECT)
613 return _POSIX_THREAD_PRIO_PROTECT;
614 #else
615 return -1;
616 #endif
617
618 case _SC_THREAD_PROCESS_SHARED:
619 #if CONF_IS_DEFINED_SET (_POSIX_THREAD_PROCESS_SHARED)
620 return _POSIX_THREAD_PROCESS_SHARED;
621 #else
622 return -1;
623 #endif
624
625 case _SC_NPROCESSORS_CONF:
626 return __get_nprocs_conf ();
627
628 case _SC_NPROCESSORS_ONLN:
629 return __get_nprocs ();
630
631 case _SC_PHYS_PAGES:
632 return __get_phys_pages ();
633
634 case _SC_AVPHYS_PAGES:
635 return __get_avphys_pages ();
636
637 case _SC_ATEXIT_MAX:
638 /* We have no limit since we use lists. */
639 return INT_MAX;
640
641 case _SC_PASS_MAX:
642 /* We have no limit but since the return value might be used to
643 allocate a buffer we restrict the value. */
644 return BUFSIZ;
645
646 case _SC_XOPEN_VERSION:
647 return _XOPEN_VERSION;
648
649 case _SC_XOPEN_XCU_VERSION:
650 return _XOPEN_XCU_VERSION;
651
652 case _SC_XOPEN_UNIX:
653 return _XOPEN_UNIX;
654
655 case _SC_XOPEN_CRYPT:
656 #ifdef _XOPEN_CRYPT
657 return _XOPEN_CRYPT;
658 #else
659 return -1;
660 #endif
661
662 case _SC_XOPEN_ENH_I18N:
663 #ifdef _XOPEN_ENH_I18N
664 return _XOPEN_ENH_I18N;
665 #else
666 return -1;
667 #endif
668
669 case _SC_XOPEN_SHM:
670 #ifdef _XOPEN_SHM
671 return _XOPEN_SHM;
672 #else
673 return -1;
674 #endif
675
676 case _SC_XOPEN_XPG2:
677 #ifdef _XOPEN_XPG2
678 return _XOPEN_XPG2;
679 #else
680 return -1;
681 #endif
682
683 case _SC_XOPEN_XPG3:
684 #ifdef _XOPEN_XPG3
685 return _XOPEN_XPG3;
686 #else
687 return -1;
688 #endif
689
690 case _SC_XOPEN_XPG4:
691 #ifdef _XOPEN_XPG4
692 return _XOPEN_XPG4;
693 #else
694 return -1;
695 #endif
696
697 case _SC_CHAR_BIT:
698 return CHAR_BIT;
699
700 case _SC_CHAR_MAX:
701 return CHAR_MAX;
702
703 case _SC_CHAR_MIN:
704 return CHAR_MIN;
705
706 case _SC_INT_MAX:
707 return INT_MAX;
708
709 case _SC_INT_MIN:
710 return INT_MIN;
711
712 case _SC_LONG_BIT:
713 return sizeof (long int) * CHAR_BIT;
714
715 case _SC_WORD_BIT:
716 return sizeof (int) * CHAR_BIT;
717
718 case _SC_MB_LEN_MAX:
719 return MB_LEN_MAX;
720
721 case _SC_NZERO:
722 return NZERO;
723
724 case _SC_SSIZE_MAX:
725 return _POSIX_SSIZE_MAX;
726
727 case _SC_SCHAR_MAX:
728 return SCHAR_MAX;
729
730 case _SC_SCHAR_MIN:
731 return SCHAR_MIN;
732
733 case _SC_SHRT_MAX:
734 return SHRT_MAX;
735
736 case _SC_SHRT_MIN:
737 return SHRT_MIN;
738
739 case _SC_UCHAR_MAX:
740 return UCHAR_MAX;
741
742 case _SC_UINT_MAX:
743 return UINT_MAX;
744
745 case _SC_ULONG_MAX:
746 return ULONG_MAX;
747
748 case _SC_USHRT_MAX:
749 return USHRT_MAX;
750
751 case _SC_NL_ARGMAX:
752 #ifdef NL_ARGMAX
753 return NL_ARGMAX;
754 #else
755 return -1;
756 #endif
757
758 case _SC_NL_LANGMAX:
759 #ifdef NL_LANGMAX
760 return NL_LANGMAX;
761 #else
762 return -1;
763 #endif
764
765 case _SC_NL_MSGMAX:
766 #ifdef NL_MSGMAX
767 return NL_MSGMAX;
768 #else
769 return -1;
770 #endif
771
772 case _SC_NL_NMAX:
773 #ifdef NL_NMAX
774 return NL_NMAX;
775 #else
776 return -1;
777 #endif
778
779 case _SC_NL_SETMAX:
780 #ifdef NL_SETMAX
781 return NL_SETMAX;
782 #else
783 return -1;
784 #endif
785
786 case _SC_NL_TEXTMAX:
787 #ifdef NL_TEXTMAX
788 return NL_TEXTMAX;
789 #else
790 return -1;
791 #endif
792
793 #define START_ENV_GROUP(VERSION) \
794 /* Empty. */
795
796 #define END_ENV_GROUP(VERSION) \
797 /* Empty. */
798
799 #define KNOWN_ABSENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX) \
800 case _SC_##SC_PREFIX##_##SUFFIX: \
801 return _##ENV_PREFIX##_##SUFFIX;
802
803 #define KNOWN_PRESENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX) \
804 case _SC_##SC_PREFIX##_##SUFFIX: \
805 return _##ENV_PREFIX##_##SUFFIX;
806
807 #define UNKNOWN_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX) \
808 case _SC_##SC_PREFIX##_##SUFFIX: \
809 return __sysconf_check_spec (#SUFFIX);
810
811 #include <posix/posix-envs.def>
812
813 #undef START_ENV_GROUP
814 #undef END_ENV_GROUP
815 #undef KNOWN_ABSENT_ENVIRONMENT
816 #undef KNOWN_PRESENT_ENVIRONMENT
817 #undef UNKNOWN_ENVIRONMENT
818
819 case _SC_XOPEN_LEGACY:
820 return _XOPEN_LEGACY;
821
822 case _SC_XOPEN_REALTIME:
823 #ifdef _XOPEN_REALTIME
824 return _XOPEN_REALTIME;
825 #else
826 return -1;
827 #endif
828 case _SC_XOPEN_REALTIME_THREADS:
829 #ifdef _XOPEN_REALTIME_THREADS
830 return _XOPEN_REALTIME_THREADS;
831 #else
832 return -1;
833 #endif
834
835 case _SC_ADVISORY_INFO:
836 #if CONF_IS_DEFINED_SET (_POSIX_ADVISORY_INFO)
837 return _POSIX_ADVISORY_INFO;
838 #else
839 return -1;
840 #endif
841
842 case _SC_BARRIERS:
843 #if CONF_IS_DEFINED_SET (_POSIX_BARRIERS)
844 return _POSIX_BARRIERS;
845 #else
846 return -1;
847 #endif
848
849 case _SC_BASE:
850 #if CONF_IS_DEFINED_SET (_POSIX_BASE)
851 return _POSIX_BASE;
852 #else
853 return -1;
854 #endif
855 case _SC_C_LANG_SUPPORT:
856 #if CONF_IS_DEFINED_SET (_POSIX_C_LANG_SUPPORT)
857 return _POSIX_C_LANG_SUPPORT;
858 #else
859 return -1;
860 #endif
861 case _SC_C_LANG_SUPPORT_R:
862 #if CONF_IS_DEFINED_SET (_POSIX_C_LANG_SUPPORT_R)
863 return _POSIX_C_LANG_SUPPORT_R;
864 #else
865 return -1;
866 #endif
867
868 case _SC_CLOCK_SELECTION:
869 #if CONF_IS_DEFINED_SET (_POSIX_CLOCK_SELECTION)
870 return _POSIX_CLOCK_SELECTION;
871 #else
872 return -1;
873 #endif
874
875 case _SC_CPUTIME:
876 #if CONF_IS_DEFINED_SET (_POSIX_CPUTIME)
877 return _POSIX_CPUTIME;
878 #else
879 return -1;
880 #endif
881
882 case _SC_DEVICE_IO:
883 #if CONF_IS_DEFINED_SET (_POSIX_DEVICE_IO)
884 return _POSIX_DEVICE_IO;
885 #else
886 return -1;
887 #endif
888 case _SC_DEVICE_SPECIFIC:
889 #if CONF_IS_DEFINED_SET (_POSIX_DEVICE_SPECIFIC)
890 return _POSIX_DEVICE_SPECIFIC;
891 #else
892 return -1;
893 #endif
894 case _SC_DEVICE_SPECIFIC_R:
895 #if CONF_IS_DEFINED_SET (_POSIX_DEVICE_SPECIFIC_R)
896 return _POSIX_DEVICE_SPECIFIC_R;
897 #else
898 return -1;
899 #endif
900
901 case _SC_FD_MGMT:
902 #if CONF_IS_DEFINED_SET (_POSIX_FD_MGMT)
903 return _POSIX_FD_MGMT;
904 #else
905 return -1;
906 #endif
907
908 case _SC_FIFO:
909 #if CONF_IS_DEFINED_SET (_POSIX_FIFO)
910 return _POSIX_FIFO;
911 #else
912 return -1;
913 #endif
914 case _SC_PIPE:
915 #if CONF_IS_DEFINED_SET (_POSIX_PIPE)
916 return _POSIX_PIPE;
917 #else
918 return -1;
919 #endif
920
921 case _SC_FILE_ATTRIBUTES:
922 #if CONF_IS_DEFINED_SET (_POSIX_FILE_ATTRIBUTES)
923 return _POSIX_FILE_ATTRIBUTES;
924 #else
925 return -1;
926 #endif
927 case _SC_FILE_LOCKING:
928 #if CONF_IS_DEFINED_SET (_POSIX_FILE_LOCKING)
929 return _POSIX_FILE_LOCKING;
930 #else
931 return -1;
932 #endif
933 case _SC_FILE_SYSTEM:
934 #if CONF_IS_DEFINED_SET (_POSIX_FILE_SYSTEM)
935 return _POSIX_FILE_SYSTEM;
936 #else
937 return -1;
938 #endif
939
940 case _SC_MONOTONIC_CLOCK:
941 #if CONF_IS_DEFINED_SET (_POSIX_MONOTONIC_CLOCK)
942 return _POSIX_MONOTONIC_CLOCK;
943 #else
944 return -1;
945 #endif
946
947 case _SC_MULTI_PROCESS:
948 #if CONF_IS_DEFINED_SET (_POSIX_MULTI_PROCESS)
949 return _POSIX_MULTI_PROCESS;
950 #else
951 return -1;
952 #endif
953 case _SC_SINGLE_PROCESS:
954 #if CONF_IS_DEFINED_SET (_POSIX_SINGLE_PROCESS)
955 return _POSIX_SINGLE_PROCESS;
956 #else
957 return -1;
958 #endif
959
960 case _SC_NETWORKING:
961 #if CONF_IS_DEFINED_SET (_POSIX_NETWORKING)
962 return _POSIX_NETWORKING;
963 #else
964 return -1;
965 #endif
966
967 case _SC_READER_WRITER_LOCKS:
968 #if CONF_IS_DEFINED_SET (_POSIX_READER_WRITER_LOCKS)
969 return _POSIX_READER_WRITER_LOCKS;
970 #else
971 return -1;
972 #endif
973 case _SC_SPIN_LOCKS:
974 #if CONF_IS_DEFINED_SET (_POSIX_SPIN_LOCKS)
975 return _POSIX_SPIN_LOCKS;
976 #else
977 return -1;
978 #endif
979
980 case _SC_REGEXP:
981 #if CONF_IS_DEFINED_SET (_POSIX_REGEXP)
982 return _POSIX_REGEXP;
983 #else
984 return -1;
985 #endif
986 /* _REGEX_VERSION has been removed with IEEE Std 1003.1-2001/Cor 2-2004,
987 item XSH/TC2/D6/137. */
988 case _SC_REGEX_VERSION:
989 return -1;
990
991 case _SC_SHELL:
992 #if CONF_IS_DEFINED_SET (_POSIX_SHELL)
993 return _POSIX_SHELL;
994 #else
995 return -1;
996 #endif
997
998 case _SC_SIGNALS:
999 #if CONF_IS_DEFINED (_POSIX_SIGNALS)
1000 return _POSIX_SIGNALS;
1001 #else
1002 return -1;
1003 #endif
1004
1005 case _SC_SPAWN:
1006 #if CONF_IS_DEFINED_SET (_POSIX_SPAWN)
1007 return _POSIX_SPAWN;
1008 #else
1009 return -1;
1010 #endif
1011
1012 case _SC_SPORADIC_SERVER:
1013 #if CONF_IS_DEFINED_SET (_POSIX_SPORADIC_SERVER)
1014 return _POSIX_SPORADIC_SERVER;
1015 #else
1016 return -1;
1017 #endif
1018 case _SC_THREAD_SPORADIC_SERVER:
1019 #if CONF_IS_DEFINED_SET (_POSIX_THREAD_SPORADIC_SERVER)
1020 return _POSIX_THREAD_SPORADIC_SERVER;
1021 #else
1022 return -1;
1023 #endif
1024
1025 case _SC_SYSTEM_DATABASE:
1026 #if CONF_IS_DEFINED_SET (_POSIX_SYSTEM_DATABASE)
1027 return _POSIX_SYSTEM_DATABASE;
1028 #else
1029 return -1;
1030 #endif
1031 case _SC_SYSTEM_DATABASE_R:
1032 #if CONF_IS_DEFINED_SET (_POSIX_SYSTEM_DATABASE_R)
1033 return _POSIX_SYSTEM_DATABASE_R;
1034 #else
1035 return -1;
1036 #endif
1037
1038 case _SC_THREAD_CPUTIME:
1039 #if CONF_IS_DEFINED_SET (_POSIX_THREAD_CPUTIME)
1040 return _POSIX_THREAD_CPUTIME;
1041 #else
1042 return -1;
1043 #endif
1044
1045 case _SC_TIMEOUTS:
1046 #if CONF_IS_DEFINED_SET (_POSIX_TIMEOUTS)
1047 return _POSIX_TIMEOUTS;
1048 #else
1049 return -1;
1050 #endif
1051
1052 case _SC_TYPED_MEMORY_OBJECTS:
1053 #if CONF_IS_DEFINED_SET (_POSIX_TYPED_MEMORY_OBJECTS)
1054 return _POSIX_TYPED_MEMORY_OBJECTS;
1055 #else
1056 return -1;
1057 #endif
1058
1059 case _SC_USER_GROUPS:
1060 #if CONF_IS_DEFINED_SET (_POSIX_USER_GROUPS)
1061 return _POSIX_USER_GROUPS;
1062 #else
1063 return -1;
1064 #endif
1065 case _SC_USER_GROUPS_R:
1066 #if CONF_IS_DEFINED_SET (_POSIX_USER_GROUPS_R)
1067 return _POSIX_USER_GROUPS_R;
1068 #else
1069 return -1;
1070 #endif
1071
1072 case _SC_2_PBS:
1073 #ifdef _POSIX2_PBS
1074 return _POSIX2_PBS;
1075 #else
1076 return -1;
1077 #endif
1078 case _SC_2_PBS_ACCOUNTING:
1079 #ifdef _POSIX2_PBS_ACCOUNTING
1080 return _POSIX2_PBS_ACCOUNTING;
1081 #else
1082 return -1;
1083 #endif
1084 case _SC_2_PBS_CHECKPOINT:
1085 #ifdef _POSIX2_PBS_CHECKPOINT
1086 return _POSIX2_PBS_CHECKPOINT;
1087 #else
1088 return -1;
1089 #endif
1090 case _SC_2_PBS_LOCATE:
1091 #ifdef _POSIX2_PBS_LOCATE
1092 return _POSIX2_PBS_LOCATE;
1093 #else
1094 return -1;
1095 #endif
1096 case _SC_2_PBS_MESSAGE:
1097 #ifdef _POSIX2_PBS_MESSAGE
1098 return _POSIX2_PBS_MESSAGE;
1099 #else
1100 return -1;
1101 #endif
1102 case _SC_2_PBS_TRACK:
1103 #ifdef _POSIX2_PBS_TRACK
1104 return _POSIX2_PBS_TRACK;
1105 #else
1106 return -1;
1107 #endif
1108
1109 case _SC_SYMLOOP_MAX:
1110 #ifdef SYMLOOP_MAX
1111 return SYMLOOP_MAX;
1112 #else
1113 return -1;
1114 #endif
1115
1116 case _SC_STREAMS:
1117 return -1;
1118
1119 case _SC_HOST_NAME_MAX:
1120 #ifdef HOST_NAME_MAX
1121 return HOST_NAME_MAX;
1122 #else
1123 return -1;
1124 #endif
1125
1126 case _SC_TRACE:
1127 #if CONF_IS_DEFINED_SET (_POSIX_TRACE)
1128 return _POSIX_TRACE;
1129 #else
1130 return -1;
1131 #endif
1132 case _SC_TRACE_EVENT_FILTER:
1133 #if CONF_IS_DEFINED_SET (_POSIX_TRACE_EVENT_FILTER)
1134 return _POSIX_TRACE_EVENT_FILTER;
1135 #else
1136 return -1;
1137 #endif
1138 case _SC_TRACE_INHERIT:
1139 #if CONF_IS_DEFINED_SET (_POSIX_TRACE_INHERIT)
1140 return _POSIX_TRACE_INHERIT;
1141 #else
1142 return -1;
1143 #endif
1144 case _SC_TRACE_LOG:
1145 #if CONF_IS_DEFINED_SET (_POSIX_TRACE_LOG)
1146 return _POSIX_TRACE_LOG;
1147 #else
1148 return -1;
1149 #endif
1150
1151 case _SC_TRACE_EVENT_NAME_MAX:
1152 case _SC_TRACE_NAME_MAX:
1153 case _SC_TRACE_SYS_MAX:
1154 case _SC_TRACE_USER_EVENT_MAX:
1155 /* No support for tracing. */
1156
1157 case _SC_XOPEN_STREAMS:
1158 /* No support for STREAMS. */
1159 return -1;
1160
1161 case _SC_LEVEL1_ICACHE_SIZE:
1162 case _SC_LEVEL1_ICACHE_ASSOC:
1163 case _SC_LEVEL1_ICACHE_LINESIZE:
1164 case _SC_LEVEL1_DCACHE_SIZE:
1165 case _SC_LEVEL1_DCACHE_ASSOC:
1166 case _SC_LEVEL1_DCACHE_LINESIZE:
1167 case _SC_LEVEL2_CACHE_SIZE:
1168 case _SC_LEVEL2_CACHE_ASSOC:
1169 case _SC_LEVEL2_CACHE_LINESIZE:
1170 case _SC_LEVEL3_CACHE_SIZE:
1171 case _SC_LEVEL3_CACHE_ASSOC:
1172 case _SC_LEVEL3_CACHE_LINESIZE:
1173 case _SC_LEVEL4_CACHE_SIZE:
1174 case _SC_LEVEL4_CACHE_ASSOC:
1175 case _SC_LEVEL4_CACHE_LINESIZE:
1176 /* In general we cannot determine these values. Therefore we
1177 return zero which indicates that no information is
1178 available. */
1179 return 0;
1180
1181 case _SC_IPV6:
1182 #if CONF_IS_DEFINED_SET (_POSIX_IPV6)
1183 return _POSIX_IPV6;
1184 #else
1185 return -1;
1186 #endif
1187
1188 case _SC_RAW_SOCKETS:
1189 #if CONF_IS_DEFINED_SET (_POSIX_RAW_SOCKETS)
1190 return _POSIX_RAW_SOCKETS;
1191 #else
1192 return -1;
1193 #endif
1194
1195 case _SC_SIGSTKSZ:
1196 #ifdef SIGSTKSZ
1197 return SIGSTKSZ;
1198 #else
1199 return -1;
1200 #endif
1201
1202 case _SC_MINSIGSTKSZ:
1203 #ifdef MINSIGSTKSZ
1204 return MINSIGSTKSZ;
1205 #else
1206 return -1;
1207 #endif
1208 }
1209 }
1210
1211 #undef __sysconf
weak_alias(__sysconf,sysconf)1212 weak_alias (__sysconf, sysconf)
1213 libc_hidden_def (__sysconf)
1214
1215 #if NEED_CHECK_SPEC
1216 static long int
1217 __sysconf_check_spec (const char *spec)
1218 {
1219 int save_errno = errno;
1220
1221 const char *getconf_dir = __libc_secure_getenv ("GETCONF_DIR") ?: GETCONF_DIR;
1222 size_t getconf_dirlen = strlen (getconf_dir);
1223 size_t speclen = strlen (spec);
1224
1225 char name[getconf_dirlen + sizeof ("/POSIX_V6_") + speclen];
1226 memcpy (mempcpy (mempcpy (name, getconf_dir, getconf_dirlen),
1227 "/POSIX_V6_", sizeof ("/POSIX_V6_") - 1),
1228 spec, speclen + 1);
1229
1230 struct __stat64_t64 st;
1231 long int ret = __stat64_time64 (name, &st) >= 0 ? 1 : -1;
1232
1233 __set_errno (save_errno);
1234 return ret;
1235 }
1236 #endif
1237