Update.
[glibc.git] / sysdeps / posix / sysconf.c
blobb0c559f70bb2ac49c99317464926a7a9c577242c
1 /* Copyright (C) 1991, 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <errno.h>
20 #include <limits.h>
21 #include <grp.h>
22 #include <pwd.h>
23 #include <stddef.h>
24 #include <stdio.h>
25 #include <time.h>
26 #include <unistd.h>
27 #include <sys/sysinfo.h>
30 /* Get the value of the system variable NAME. */
31 long int
32 __sysconf (name)
33 int name;
35 switch (name)
37 default:
38 __set_errno (EINVAL);
39 return -1;
41 case _SC_ARG_MAX:
42 #ifdef ARG_MAX
43 return ARG_MAX;
44 #else
45 return -1;
46 #endif
48 case _SC_CHILD_MAX:
49 #ifdef CHILD_MAX
50 return CHILD_MAX;
51 #else
52 return -1;
53 #endif
55 case _SC_CLK_TCK:
56 #ifdef CLK_TCK
57 return CLK_TCK;
58 #else
59 return 60;
60 #endif
62 case _SC_NGROUPS_MAX:
63 #ifdef NGROUPS_MAX
64 return NGROUPS_MAX;
65 #else
66 return -1;
67 #endif
69 case _SC_OPEN_MAX:
70 return __getdtablesize ();
72 case _SC_STREAM_MAX:
73 #ifdef STREAM_MAX
74 return STREAM_MAX;
75 #else
76 return FOPEN_MAX;
77 #endif
79 case _SC_TZNAME_MAX:
80 return __tzname_max ();
82 case _SC_JOB_CONTROL:
83 #ifdef _POSIX_JOB_CONTROL
84 return 1;
85 #else
86 return -1;
87 #endif
89 case _SC_SAVED_IDS:
90 #ifdef _POSIX_SAVED_IDS
91 return 1;
92 #else
93 return -1;
94 #endif
96 case _SC_REALTIME_SIGNALS:
97 #ifdef _POSIX_REALTIME_SIGNALS
98 return 1;
99 #else
100 return -1;
101 #endif
103 case _SC_PRIORITY_SCHEDULING:
104 #ifdef _POSIX_PRIORITY_SCHEDULING
105 return 1;
106 #else
107 return -1;
108 #endif
110 case _SC_TIMERS:
111 #ifdef _POSIX_TIMERS
112 return 1;
113 #else
114 return -1;
115 #endif
117 case _SC_ASYNCHRONOUS_IO:
118 #ifdef _POSIX_ASYNCHRONOUS_IO
119 return 1;
120 #else
121 return -1;
122 #endif
124 case _SC_PRIORITIZED_IO:
125 #ifdef _POSIX_PRIORITIZED_IO
126 return 1;
127 #else
128 return -1;
129 #endif
131 case _SC_SYNCHRONIZED_IO:
132 #ifdef _POSIX_SYNCHRONIZED_IO
133 return 1;
134 #else
135 return -1;
136 #endif
138 case _SC_FSYNC:
139 #ifdef _POSIX_FSYNC
140 return 1;
141 #else
142 return -1;
143 #endif
145 case _SC_MAPPED_FILES:
146 #ifdef _POSIX_MAPPED_FILES
147 return 1;
148 #else
149 return -1;
150 #endif
152 case _SC_MEMLOCK:
153 #ifdef _POSIX_MEMLOCK
154 return 1;
155 #else
156 return -1;
157 #endif
159 case _SC_MEMLOCK_RANGE:
160 #ifdef _POSIX_MEMLOCK_RANGE
161 return 1;
162 #else
163 return -1;
164 #endif
166 case _SC_MEMORY_PROTECTION:
167 #ifdef _POSIX_MEMORY_PROTECTION
168 return 1;
169 #else
170 return -1;
171 #endif
173 case _SC_MESSAGE_PASSING:
174 #ifdef _POSIX_MESSAGE_PASSING
175 return 1;
176 #else
177 return -1;
178 #endif
180 case _SC_SEMAPHORES:
181 #ifdef _POSIX_SEMAPHORES
182 return 1;
183 #else
184 return -1;
185 #endif
187 case _SC_SHARED_MEMORY_OBJECTS:
188 #ifdef _POSIX_SHARED_MEMORY_OBJECTS
189 return 1;
190 #else
191 return -1;
192 #endif
194 case _SC_VERSION:
195 return _POSIX_VERSION;
197 case _SC_PAGESIZE:
198 return __getpagesize ();
200 case _SC_AIO_LISTIO_MAX:
201 #ifdef AIO_LISTIO_MAX
202 return AIO_LISTIO_MAX;
203 #else
204 return -1;
205 #endif
207 case _SC_AIO_MAX:
208 #ifdef AIO_MAX
209 return AIO_MAX;
210 #else
211 return -1;
212 #endif
214 case _SC_AIO_PRIO_DELTA_MAX:
215 #ifdef AIO_PRIO_DELTA_MAX
216 return AIO_PRIO_DELTA_MAX;
217 #else
218 return -1;
219 #endif
221 case _SC_DELAYTIMER_MAX:
222 #ifdef DELAYTIMER_MAX
223 return DELAYTIMER_MAX;
224 #else
225 return -1;
226 #endif
228 case _SC_MQ_OPEN_MAX:
229 #ifdef MQ_OPEN_MAX
230 return MQ_OPEN_MAX;
231 #else
232 return -1;
233 #endif
235 case _SC_MQ_PRIO_MAX:
236 #ifdef MQ_PRIO_MAX
237 return MQ_PRIO_MAX;
238 #else
239 return -1;
240 #endif
242 case _SC_RTSIG_MAX:
243 #ifdef RTSIG_MAX
244 return RTSIG_MAX;
245 #else
246 return -1;
247 #endif
249 case _SC_SEM_NSEMS_MAX:
250 #ifdef SEM_NSEMS_MAX
251 return SEM_NSEMS_MAX;
252 #else
253 return -1;
254 #endif
256 case _SC_SEM_VALUE_MAX:
257 #ifdef SEM_VALUE_MAX
258 return SEM_VALUE_MAX;
259 #else
260 return -1;
261 #endif
263 case _SC_SIGQUEUE_MAX:
264 #ifdef SIGQUEUE_MAX
265 return SIGQUEUE_MAX;
266 #else
267 return -1;
268 #endif
270 case _SC_TIMER_MAX:
271 #ifdef TIMER_MAX
272 return TIMER_MAX;
273 #else
274 return -1;
275 #endif
277 case _SC_BC_BASE_MAX:
278 #ifdef BC_BASE_MAX
279 return BC_BASE_MAX;
280 #else
281 return -1;
282 #endif
284 case _SC_BC_DIM_MAX:
285 #ifdef BC_DIM_MAX
286 return BC_DIM_MAX;
287 #else
288 return -1;
289 #endif
291 case _SC_BC_SCALE_MAX:
292 #ifdef BC_SCALE_MAX
293 return BC_SCALE_MAX;
294 #else
295 return -1;
296 #endif
298 case _SC_BC_STRING_MAX:
299 #ifdef BC_STRING_MAX
300 return BC_STRING_MAX;
301 #else
302 return -1;
303 #endif
305 case _SC_COLL_WEIGHTS_MAX:
306 #ifdef COLL_WEIGHTS_MAX
307 return COLL_WEIGHTS_MAX;
308 #else
309 return -1;
310 #endif
312 case _SC_EQUIV_CLASS_MAX:
313 #ifdef EQUIV_CLASS_MAX
314 return EQUIV_CLASS_MAX;
315 #else
316 return -1;
317 #endif
319 case _SC_EXPR_NEST_MAX:
320 #ifdef EXPR_NEST_MAX
321 return EXPR_NEST_MAX;
322 #else
323 return -1;
324 #endif
326 case _SC_LINE_MAX:
327 #ifdef LINE_MAX
328 return LINE_MAX;
329 #else
330 return -1;
331 #endif
333 case _SC_RE_DUP_MAX:
334 #ifdef RE_DUP_MAX
335 return RE_DUP_MAX;
336 #else
337 return -1;
338 #endif
340 case _SC_CHARCLASS_NAME_MAX:
341 #ifdef CHARCLASS_NAME_MAX
342 return CHARCLASS_NAME_MAX;
343 #else
344 return -1;
345 #endif
347 case _SC_PII:
348 #ifdef _POSIX_PII
349 return 1;
350 #else
351 return -1;
352 #endif
354 case _SC_PII_XTI:
355 #ifdef _POSIX_PII_XTI
356 return 1;
357 #else
358 return -1;
359 #endif
361 case _SC_PII_SOCKET:
362 #ifdef _POSIX_PII_SOCKET
363 return 1;
364 #else
365 return -1;
366 #endif
368 case _SC_PII_INTERNET:
369 #ifdef _POSIX_PII_INTERNET
370 return 1;
371 #else
372 return -1;
373 #endif
375 case _SC_PII_OSI:
376 #ifdef _POSIX_PII_OSI
377 return 1;
378 #else
379 return -1;
380 #endif
382 case _SC_POLL:
383 #ifdef _POSIX_POLL
384 return 1;
385 #else
386 return -1;
387 #endif
389 case _SC_SELECT:
390 #ifdef _POSIX_SELECT
391 return 1;
392 #else
393 return -1;
394 #endif
396 case _SC_UIO_MAXIOV:
397 #ifdef UIO_MAXIOV
398 return UIO_MAXIOV;
399 #else
400 return -1;
401 #endif
403 case _SC_PII_INTERNET_STREAM:
404 #ifdef _POSIX_PII_INTERNET_STREAM
405 return 1;
406 #else
407 return -1;
408 #endif
410 case _SC_PII_INTERNET_DGRAM:
411 #ifdef _POSIX_PII_INTERNET_DGRAM
412 return 1;
413 #else
414 return -1;
415 #endif
417 case _SC_PII_OSI_COTS:
418 #ifdef _POSIX_PII_OSI_COTS
419 return 1;
420 #else
421 return -1;
422 #endif
424 case _SC_PII_OSI_CLTS:
425 #ifdef _POSIX_PII_OSI_CLTS
426 return 1;
427 #else
428 return -1;
429 #endif
431 case _SC_PII_OSI_M:
432 #ifdef _POSIX_PII_OSI_M
433 return 1;
434 #else
435 return -1;
436 #endif
438 case _SC_T_IOV_MAX:
439 #ifdef _T_IOV_MAX
440 return _T_IOV_MAX;
441 #else
442 return -1;
443 #endif
445 case _SC_2_VERSION:
446 return _POSIX2_VERSION;
448 case _SC_2_C_BIND:
449 #ifdef _POSIX2_C_BIND
450 return _POSIX2_C_BIND;
451 #else
452 return -1;
453 #endif
455 case _SC_2_C_DEV:
456 #ifdef _POSIX2_C_DEV
457 return _POSIX2_C_DEV;
458 #else
459 return -1;
460 #endif
462 case _SC_2_C_VERSION:
463 #ifdef _POSIX2_C_VERSION
464 return _POSIX2_C_VERSION;
465 #else
466 return -1;
467 #endif
469 case _SC_2_FORT_DEV:
470 #ifdef _POSIX2_FORT_DEV
471 return _POSIX2_FORT_DEV;
472 #else
473 return -1;
474 #endif
476 case _SC_2_LOCALEDEF:
477 #ifdef _POSIX2_LOCALEDEF
478 return _POSIX2_LOCALEDEF;
479 #else
480 return -1;
481 #endif
483 case _SC_2_SW_DEV:
484 #ifdef _POSIX2_SW_DEV
485 return _POSIX2_SW_DEV;
486 #else
487 return -1;
488 #endif
490 case _SC_2_CHAR_TERM:
491 #ifdef _POSIX2_CHAR_TERM
492 return _POSIX2_CHAR_TERM;
493 #else
494 return -1;
495 #endif
497 case _SC_2_UPE:
498 #ifdef _POSIX2_UPE
499 return _POSIX2_UPE;
500 #else
501 return -1;
502 #endif
504 /* POSIX 1003.1c (POSIX Threads). */
505 case _SC_THREADS:
506 #ifdef _POSIX_THREADS
507 return 1;
508 #else
509 return -1;
510 #endif
512 case _SC_THREAD_SAFE_FUNCTIONS:
513 #ifdef _POSIX_THREAD_SAFE_FUNCTIONS
514 return 1;
515 #else
516 return -1;
517 #endif
519 case _SC_GETGR_R_SIZE_MAX:
520 #ifdef NSS_BUFLEN_GROUP
521 return NSS_BUFLEN_GROUP;
522 #else
523 return -1;
524 #endif
526 case _SC_GETPW_R_SIZE_MAX:
527 #ifdef NSS_BUFLEN_PASSWD
528 return NSS_BUFLEN_PASSWD;
529 #else
530 return -1;
531 #endif
533 case _SC_LOGIN_NAME_MAX:
534 #ifdef _POSIX_LOGIN_NAME_MAX
535 return _POSIX_LOGIN_NAME_MAX;
536 #else
537 return -1;
538 #endif
540 case _SC_TTY_NAME_MAX:
541 #ifdef _POSIX_TTY_NAME_MAX
542 return _POSIX_TTY_NAME_MAX;
543 #else
544 return -1;
545 #endif
547 case _SC_THREAD_DESTRUCTOR_ITERATIONS:
548 #ifdef _POSIX_THREAD_DESTRUCTOR_ITERATIONS
549 return _POSIX_THREAD_DESTRUCTOR_ITERATIONS;
550 #else
551 return -1;
552 #endif
554 case _SC_THREAD_KEYS_MAX:
555 #ifdef PTHREAD_KEYS_MAX
556 return PTHREAD_KEYS_MAX;
557 #else
558 return -1;
559 #endif
561 case _SC_THREAD_STACK_MIN:
562 #ifdef PTHREAD_STACK_MIN
563 return PTHREAD_STACK_MIN;
564 #else
565 return -1;
566 #endif
568 case _SC_THREAD_THREADS_MAX:
569 #ifdef PTHREAD_THREADS_MAX
570 return PTHREAD_THREADS_MAX;
571 #else
572 return -1;
573 #endif
575 case _SC_THREAD_ATTR_STACKADDR:
576 #ifdef _POSIX_THREAD_ATTR_STACKADDR
577 return 1;
578 #else
579 return -1;
580 #endif
582 case _SC_THREAD_ATTR_STACKSIZE:
583 #ifdef _POSIX_THREAD_ATTR_STACKSIZE
584 return 1;
585 #else
586 return -1;
587 #endif
589 case _SC_THREAD_PRIORITY_SCHEDULING:
590 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
591 return 1;
592 #else
593 return -1;
594 #endif
596 case _SC_THREAD_PRIO_INHERIT:
597 #ifdef _POSIX_THREAD_PRIO_INHERIT
598 return 1;
599 #else
600 return -1;
601 #endif
603 case _SC_THREAD_PRIO_PROTECT:
604 #ifdef _POSIX_THREAD_PRIO_PROTECT
605 return 1;
606 #else
607 return -1;
608 #endif
610 case _SC_THREAD_PROCESS_SHARED:
611 #ifdef _POSIX_THREAD_PROCESS_SHARED
612 return 1;
613 #else
614 return -1;
615 #endif
617 case _SC_NPROCESSORS_CONF:
618 return __get_nprocs_conf ();
620 case _SC_NPROCESSORS_ONLN:
621 return __get_nprocs ();
623 case _SC_PHYS_PAGES:
624 return __get_phys_pages ();
626 case _SC_AVPHYS_PAGES:
627 return __get_avphys_pages ();
629 case _SC_ATEXIT_MAX:
630 /* We have no limit since we use lists. */
631 return INT_MAX;
633 case _SC_PASS_MAX:
634 /* We have no limit but since the return value might be used to
635 allocate a buffer we restrict the value. */
636 return BUFSIZ;
638 case _SC_XOPEN_VERSION:
639 return _XOPEN_VERSION;
641 case _SC_XOPEN_XCU_VERSION:
642 return _XOPEN_XCU_VERSION;
644 case _SC_XOPEN_UNIX:
645 return _XOPEN_UNIX;
647 case _SC_XOPEN_CRYPT:
648 #ifdef _XOPEN_CRYPT
649 return _XOPEN_CRYPT;
650 #else
651 return -1;
652 #endif
654 case _SC_XOPEN_ENH_I18N:
655 #ifdef _XOPEN_ENH_I18N
656 return _XOPEN_ENH_I18N;
657 #else
658 return -1;
659 #endif
661 case _SC_XOPEN_SHM:
662 #ifdef _XOPEN_SHM
663 return _XOPEN_SHM;
664 #else
665 return -1;
666 #endif
668 case _SC_XOPEN_XPG2:
669 #ifdef _XOPEN_XPG2
670 return _XOPEN_XPG2;
671 #else
672 return -1;
673 #endif
675 case _SC_XOPEN_XPG3:
676 #ifdef _XOPEN_XPG3
677 return _XOPEN_XPG3;
678 #else
679 return -1;
680 #endif
682 case _SC_XOPEN_XPG4:
683 #ifdef _XOPEN_XPG4
684 return _XOPEN_XPG4;
685 #else
686 return -1;
687 #endif
689 case _SC_CHAR_BIT:
690 return CHAR_BIT;
692 case _SC_CHAR_MAX:
693 return CHAR_MAX;
695 case _SC_CHAR_MIN:
696 return CHAR_MIN;
698 case _SC_INT_MAX:
699 return INT_MAX;
701 case _SC_INT_MIN:
702 return INT_MIN;
704 case _SC_LONG_BIT:
705 return sizeof (long int) * CHAR_BIT;
707 case _SC_WORD_BIT:
708 return sizeof (int) * CHAR_BIT;
710 case _SC_MB_LEN_MAX:
711 return MB_LEN_MAX;
713 case _SC_NZERO:
714 return NZERO;
716 case _SC_SSIZE_MAX:
717 return _POSIX_SSIZE_MAX;
719 case _SC_SCHAR_MAX:
720 return SCHAR_MAX;
722 case _SC_SCHAR_MIN:
723 return SCHAR_MIN;
725 case _SC_SHRT_MAX:
726 return SHRT_MAX;
728 case _SC_SHRT_MIN:
729 return SHRT_MIN;
731 case _SC_UCHAR_MAX:
732 return UCHAR_MAX;
734 case _SC_UINT_MAX:
735 return UINT_MAX;
737 case _SC_ULONG_MAX:
738 return ULONG_MAX;
740 case _SC_USHRT_MAX:
741 return USHRT_MAX;
743 case _SC_NL_ARGMAX:
744 #ifdef NL_ARGMAX
745 return NL_ARGMAX;
746 #else
747 return -1;
748 #endif
750 case _SC_NL_LANGMAX:
751 #ifdef NL_LANGMAX
752 return NL_LANGMAX;
753 #else
754 return -1;
755 #endif
757 case _SC_NL_MSGMAX:
758 #ifdef NL_MSGMAX
759 return NL_MSGMAX;
760 #else
761 return -1;
762 #endif
764 case _SC_NL_NMAX:
765 #ifdef NL_NMAX
766 return NL_NMAX;
767 #else
768 return -1;
769 #endif
771 case _SC_NL_SETMAX:
772 #ifdef NL_SETMAX
773 return NL_SETMAX;
774 #else
775 return -1;
776 #endif
778 case _SC_NL_TEXTMAX:
779 #ifdef NL_TEXTMAX
780 return NL_TEXTMAX;
781 #else
782 return -1;
783 #endif
785 case _SC_XBS5_ILP32_OFF32:
786 #ifdef _XBS5_ILP32_OFF32
787 return _XBS5_ILP32_OFF32;
788 #else
789 return -1;
790 #endif
791 case _SC_XBS5_ILP32_OFFBIG:
792 #ifdef _XBS5_ILP32_OFFBIG
793 return _XBS5_ILP32_OFFBIG;
794 #else
795 return -1;
796 #endif
797 case _SC_XBS5_LP64_OFF64:
798 #ifdef _XBS5_LP64_OFF64
799 return _XBS5_LP64_OFF64;
800 #else
801 return -1;
802 #endif
803 case _SC_XBS5_LPBIG_OFFBIG:
804 #ifdef _XBS5_LPBIG_OFFBIG
805 return _XBS5_LPBIG_OFFBIG;
806 #else
807 return -1;
808 #endif
810 case _SC_XOPEN_LEGACY:
811 return _XOPEN_LEGACY;
813 case _SC_XOPEN_REALTIME:
814 #ifdef _XOPEN_REALTIME
815 return _XOPEN_REALTIME;
816 #else
817 return -1;
818 #endif
819 case _SC_XOPEN_REALTIME_THREADS:
820 #ifdef _XOPEN_REALTIME_THREADS
821 return _XOPEN_REALTIME_THREADS;
822 #else
823 return -1;
824 #endif
828 weak_alias (__sysconf, sysconf)