Fix tzfile.c namespace (bug 17583).
[glibc.git] / posix / getconf.c
blob14d51d87acf7b08cfe7694190b3faa6049847d9f
1 /* Copyright (C) 1991-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation; version 2 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */
17 #include <unistd.h>
18 #include <errno.h>
19 #include <error.h>
20 #include <libintl.h>
21 #include <locale.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <stdio.h>
26 #include "../version.h"
27 #define PACKAGE _libc_intl_domainname
29 struct conf
31 const char *name;
32 const int call_name;
33 const enum { SYSCONF, CONFSTR, PATHCONF } call;
36 static const struct conf vars[] =
38 { "LINK_MAX", _PC_LINK_MAX, PATHCONF },
39 { "_POSIX_LINK_MAX", _PC_LINK_MAX, PATHCONF },
40 { "MAX_CANON", _PC_MAX_CANON, PATHCONF },
41 { "_POSIX_MAX_CANON", _PC_MAX_CANON, PATHCONF },
42 { "MAX_INPUT", _PC_MAX_INPUT, PATHCONF },
43 { "_POSIX_MAX_INPUT", _PC_MAX_INPUT, PATHCONF },
44 { "NAME_MAX", _PC_NAME_MAX, PATHCONF },
45 { "_POSIX_NAME_MAX", _PC_NAME_MAX, PATHCONF },
46 { "PATH_MAX", _PC_PATH_MAX, PATHCONF },
47 { "_POSIX_PATH_MAX", _PC_PATH_MAX, PATHCONF },
48 { "PIPE_BUF", _PC_PIPE_BUF, PATHCONF },
49 { "_POSIX_PIPE_BUF", _PC_PIPE_BUF, PATHCONF },
50 { "SOCK_MAXBUF", _PC_SOCK_MAXBUF, PATHCONF },
51 { "_POSIX_ASYNC_IO", _PC_ASYNC_IO, PATHCONF },
52 { "_POSIX_CHOWN_RESTRICTED", _PC_CHOWN_RESTRICTED, PATHCONF },
53 { "_POSIX_NO_TRUNC", _PC_NO_TRUNC, PATHCONF },
54 { "_POSIX_PRIO_IO", _PC_PRIO_IO, PATHCONF },
55 { "_POSIX_SYNC_IO", _PC_SYNC_IO, PATHCONF },
56 { "_POSIX_VDISABLE", _PC_VDISABLE, PATHCONF },
58 { "ARG_MAX", _SC_ARG_MAX, SYSCONF },
59 { "ATEXIT_MAX", _SC_ATEXIT_MAX, SYSCONF },
60 { "CHAR_BIT", _SC_CHAR_BIT, SYSCONF },
61 { "CHAR_MAX", _SC_CHAR_MAX, SYSCONF },
62 { "CHAR_MIN", _SC_CHAR_MIN, SYSCONF },
63 { "CHILD_MAX", _SC_CHILD_MAX, SYSCONF },
64 { "CLK_TCK", _SC_CLK_TCK, SYSCONF },
65 { "INT_MAX", _SC_INT_MAX, SYSCONF },
66 { "INT_MIN", _SC_INT_MIN, SYSCONF },
67 { "IOV_MAX", _SC_UIO_MAXIOV, SYSCONF },
68 { "LOGNAME_MAX", _SC_LOGIN_NAME_MAX, SYSCONF },
69 { "LONG_BIT", _SC_LONG_BIT, SYSCONF },
70 { "MB_LEN_MAX", _SC_MB_LEN_MAX, SYSCONF },
71 { "NGROUPS_MAX", _SC_NGROUPS_MAX, SYSCONF },
72 { "NL_ARGMAX", _SC_NL_ARGMAX, SYSCONF },
73 { "NL_LANGMAX", _SC_NL_LANGMAX, SYSCONF },
74 { "NL_MSGMAX", _SC_NL_MSGMAX, SYSCONF },
75 { "NL_NMAX", _SC_NL_NMAX, SYSCONF },
76 { "NL_SETMAX", _SC_NL_SETMAX, SYSCONF },
77 { "NL_TEXTMAX", _SC_NL_TEXTMAX, SYSCONF },
78 { "NSS_BUFLEN_GROUP", _SC_GETGR_R_SIZE_MAX, SYSCONF },
79 { "NSS_BUFLEN_PASSWD", _SC_GETPW_R_SIZE_MAX, SYSCONF },
80 { "NZERO", _SC_NZERO, SYSCONF },
81 { "OPEN_MAX", _SC_OPEN_MAX, SYSCONF },
82 { "PAGESIZE", _SC_PAGESIZE, SYSCONF },
83 { "PAGE_SIZE", _SC_PAGESIZE, SYSCONF },
84 { "PASS_MAX", _SC_PASS_MAX, SYSCONF },
85 { "PTHREAD_DESTRUCTOR_ITERATIONS", _SC_THREAD_DESTRUCTOR_ITERATIONS, SYSCONF },
86 { "PTHREAD_KEYS_MAX", _SC_THREAD_KEYS_MAX, SYSCONF },
87 { "PTHREAD_STACK_MIN", _SC_THREAD_STACK_MIN, SYSCONF },
88 { "PTHREAD_THREADS_MAX", _SC_THREAD_THREADS_MAX, SYSCONF },
89 { "SCHAR_MAX", _SC_SCHAR_MAX, SYSCONF },
90 { "SCHAR_MIN", _SC_SCHAR_MIN, SYSCONF },
91 { "SHRT_MAX", _SC_SHRT_MAX, SYSCONF },
92 { "SHRT_MIN", _SC_SHRT_MIN, SYSCONF },
93 { "SSIZE_MAX", _SC_SSIZE_MAX, SYSCONF },
94 { "TTY_NAME_MAX", _SC_TTY_NAME_MAX, SYSCONF },
95 { "TZNAME_MAX", _SC_TZNAME_MAX, SYSCONF },
96 { "UCHAR_MAX", _SC_UCHAR_MAX, SYSCONF },
97 { "UINT_MAX", _SC_UINT_MAX, SYSCONF },
98 { "UIO_MAXIOV", _SC_UIO_MAXIOV, SYSCONF },
99 { "ULONG_MAX", _SC_ULONG_MAX, SYSCONF },
100 { "USHRT_MAX", _SC_USHRT_MAX, SYSCONF },
101 { "WORD_BIT", _SC_WORD_BIT, SYSCONF },
102 { "_AVPHYS_PAGES", _SC_AVPHYS_PAGES, SYSCONF },
103 { "_NPROCESSORS_CONF", _SC_NPROCESSORS_CONF, SYSCONF },
104 { "_NPROCESSORS_ONLN", _SC_NPROCESSORS_ONLN, SYSCONF },
105 { "_PHYS_PAGES", _SC_PHYS_PAGES, SYSCONF },
106 { "_POSIX_ARG_MAX", _SC_ARG_MAX, SYSCONF },
107 { "_POSIX_ASYNCHRONOUS_IO", _SC_ASYNCHRONOUS_IO, SYSCONF },
108 { "_POSIX_CHILD_MAX", _SC_CHILD_MAX, SYSCONF },
109 { "_POSIX_FSYNC", _SC_FSYNC, SYSCONF },
110 { "_POSIX_JOB_CONTROL", _SC_JOB_CONTROL, SYSCONF },
111 { "_POSIX_MAPPED_FILES", _SC_MAPPED_FILES, SYSCONF },
112 { "_POSIX_MEMLOCK", _SC_MEMLOCK, SYSCONF },
113 { "_POSIX_MEMLOCK_RANGE", _SC_MEMLOCK_RANGE, SYSCONF },
114 { "_POSIX_MEMORY_PROTECTION", _SC_MEMORY_PROTECTION, SYSCONF },
115 { "_POSIX_MESSAGE_PASSING", _SC_MESSAGE_PASSING, SYSCONF },
116 { "_POSIX_NGROUPS_MAX", _SC_NGROUPS_MAX, SYSCONF },
117 { "_POSIX_OPEN_MAX", _SC_OPEN_MAX, SYSCONF },
118 { "_POSIX_PII", _SC_PII, SYSCONF },
119 { "_POSIX_PII_INTERNET", _SC_PII_INTERNET, SYSCONF },
120 { "_POSIX_PII_INTERNET_DGRAM", _SC_PII_INTERNET_DGRAM, SYSCONF },
121 { "_POSIX_PII_INTERNET_STREAM", _SC_PII_INTERNET_STREAM, SYSCONF },
122 { "_POSIX_PII_OSI", _SC_PII_OSI, SYSCONF },
123 { "_POSIX_PII_OSI_CLTS", _SC_PII_OSI_CLTS, SYSCONF },
124 { "_POSIX_PII_OSI_COTS", _SC_PII_OSI_COTS, SYSCONF },
125 { "_POSIX_PII_OSI_M", _SC_PII_OSI_M, SYSCONF },
126 { "_POSIX_PII_SOCKET", _SC_PII_SOCKET, SYSCONF },
127 { "_POSIX_PII_XTI", _SC_PII_XTI, SYSCONF },
128 { "_POSIX_POLL", _SC_POLL, SYSCONF },
129 { "_POSIX_PRIORITIZED_IO", _SC_PRIORITIZED_IO, SYSCONF },
130 { "_POSIX_PRIORITY_SCHEDULING", _SC_PRIORITY_SCHEDULING, SYSCONF },
131 { "_POSIX_REALTIME_SIGNALS", _SC_REALTIME_SIGNALS, SYSCONF },
132 { "_POSIX_SAVED_IDS", _SC_SAVED_IDS, SYSCONF },
133 { "_POSIX_SELECT", _SC_SELECT, SYSCONF },
134 { "_POSIX_SEMAPHORES", _SC_SEMAPHORES, SYSCONF },
135 { "_POSIX_SHARED_MEMORY_OBJECTS", _SC_SHARED_MEMORY_OBJECTS, SYSCONF },
136 { "_POSIX_SSIZE_MAX", _SC_SSIZE_MAX, SYSCONF },
137 { "_POSIX_STREAM_MAX", _SC_STREAM_MAX, SYSCONF },
138 { "_POSIX_SYNCHRONIZED_IO", _SC_SYNCHRONIZED_IO, SYSCONF },
139 { "_POSIX_THREADS", _SC_THREADS, SYSCONF },
140 { "_POSIX_THREAD_ATTR_STACKADDR", _SC_THREAD_ATTR_STACKADDR, SYSCONF },
141 { "_POSIX_THREAD_ATTR_STACKSIZE", _SC_THREAD_ATTR_STACKSIZE, SYSCONF },
142 { "_POSIX_THREAD_PRIORITY_SCHEDULING", _SC_THREAD_PRIORITY_SCHEDULING, SYSCONF },
143 { "_POSIX_THREAD_PRIO_INHERIT", _SC_THREAD_PRIO_INHERIT, SYSCONF },
144 { "_POSIX_THREAD_PRIO_PROTECT", _SC_THREAD_PRIO_PROTECT, SYSCONF },
145 { "_POSIX_THREAD_ROBUST_PRIO_INHERIT", _SC_THREAD_ROBUST_PRIO_INHERIT,
146 SYSCONF },
147 { "_POSIX_THREAD_ROBUST_PRIO_PROTECT", _SC_THREAD_ROBUST_PRIO_PROTECT,
148 SYSCONF },
149 { "_POSIX_THREAD_PROCESS_SHARED", _SC_THREAD_PROCESS_SHARED, SYSCONF },
150 { "_POSIX_THREAD_SAFE_FUNCTIONS", _SC_THREAD_SAFE_FUNCTIONS, SYSCONF },
151 { "_POSIX_TIMERS", _SC_TIMERS, SYSCONF },
152 { "TIMER_MAX", _SC_TIMER_MAX, SYSCONF },
153 { "_POSIX_TZNAME_MAX", _SC_TZNAME_MAX, SYSCONF },
154 { "_POSIX_VERSION", _SC_VERSION, SYSCONF },
155 { "_T_IOV_MAX", _SC_T_IOV_MAX, SYSCONF },
156 { "_XOPEN_CRYPT", _SC_XOPEN_CRYPT, SYSCONF },
157 { "_XOPEN_ENH_I18N", _SC_XOPEN_ENH_I18N, SYSCONF },
158 { "_XOPEN_LEGACY", _SC_XOPEN_LEGACY, SYSCONF },
159 { "_XOPEN_REALTIME", _SC_XOPEN_REALTIME, SYSCONF },
160 { "_XOPEN_REALTIME_THREADS", _SC_XOPEN_REALTIME_THREADS, SYSCONF },
161 { "_XOPEN_SHM", _SC_XOPEN_SHM, SYSCONF },
162 { "_XOPEN_UNIX", _SC_XOPEN_UNIX, SYSCONF },
163 { "_XOPEN_VERSION", _SC_XOPEN_VERSION, SYSCONF },
164 { "_XOPEN_XCU_VERSION", _SC_XOPEN_XCU_VERSION, SYSCONF },
165 { "_XOPEN_XPG2", _SC_XOPEN_XPG2, SYSCONF },
166 { "_XOPEN_XPG3", _SC_XOPEN_XPG3, SYSCONF },
167 { "_XOPEN_XPG4", _SC_XOPEN_XPG4, SYSCONF },
168 /* POSIX.2 */
169 { "BC_BASE_MAX", _SC_BC_BASE_MAX, SYSCONF },
170 { "BC_DIM_MAX", _SC_BC_DIM_MAX, SYSCONF },
171 { "BC_SCALE_MAX", _SC_BC_SCALE_MAX, SYSCONF },
172 { "BC_STRING_MAX", _SC_BC_STRING_MAX, SYSCONF },
173 { "CHARCLASS_NAME_MAX", _SC_CHARCLASS_NAME_MAX, SYSCONF },
174 { "COLL_WEIGHTS_MAX", _SC_COLL_WEIGHTS_MAX, SYSCONF },
175 { "EQUIV_CLASS_MAX", _SC_EQUIV_CLASS_MAX, SYSCONF },
176 { "EXPR_NEST_MAX", _SC_EXPR_NEST_MAX, SYSCONF },
177 { "LINE_MAX", _SC_LINE_MAX, SYSCONF },
178 { "POSIX2_BC_BASE_MAX", _SC_BC_BASE_MAX, SYSCONF },
179 { "POSIX2_BC_DIM_MAX", _SC_BC_DIM_MAX, SYSCONF },
180 { "POSIX2_BC_SCALE_MAX", _SC_BC_SCALE_MAX, SYSCONF },
181 { "POSIX2_BC_STRING_MAX", _SC_BC_STRING_MAX, SYSCONF },
182 { "POSIX2_CHAR_TERM", _SC_2_CHAR_TERM, SYSCONF },
183 { "POSIX2_COLL_WEIGHTS_MAX", _SC_COLL_WEIGHTS_MAX, SYSCONF },
184 { "POSIX2_C_BIND", _SC_2_C_BIND, SYSCONF },
185 { "POSIX2_C_DEV", _SC_2_C_DEV, SYSCONF },
186 { "POSIX2_C_VERSION", _SC_2_C_VERSION, SYSCONF },
187 { "POSIX2_EXPR_NEST_MAX", _SC_EXPR_NEST_MAX, SYSCONF },
188 { "POSIX2_FORT_DEV", _SC_2_FORT_DEV, SYSCONF },
189 { "POSIX2_FORT_RUN", _SC_2_FORT_RUN, SYSCONF },
190 { "_POSIX2_LINE_MAX", _SC_LINE_MAX, SYSCONF },
191 { "POSIX2_LINE_MAX", _SC_LINE_MAX, SYSCONF },
192 { "POSIX2_LOCALEDEF", _SC_2_LOCALEDEF, SYSCONF },
193 { "POSIX2_RE_DUP_MAX", _SC_RE_DUP_MAX, SYSCONF },
194 { "POSIX2_SW_DEV", _SC_2_SW_DEV, SYSCONF },
195 { "POSIX2_UPE", _SC_2_UPE, SYSCONF },
196 { "POSIX2_VERSION", _SC_2_VERSION, SYSCONF },
197 { "RE_DUP_MAX", _SC_RE_DUP_MAX, SYSCONF },
199 { "PATH", _CS_PATH, CONFSTR },
200 { "CS_PATH", _CS_PATH, CONFSTR },
202 /* LFS */
203 { "LFS_CFLAGS", _CS_LFS_CFLAGS, CONFSTR },
204 { "LFS_LDFLAGS", _CS_LFS_LDFLAGS, CONFSTR },
205 { "LFS_LIBS", _CS_LFS_LIBS, CONFSTR },
206 { "LFS_LINTFLAGS", _CS_LFS_LINTFLAGS, CONFSTR },
207 { "LFS64_CFLAGS", _CS_LFS64_CFLAGS, CONFSTR },
208 { "LFS64_LDFLAGS", _CS_LFS64_LDFLAGS, CONFSTR },
209 { "LFS64_LIBS", _CS_LFS64_LIBS, CONFSTR },
210 { "LFS64_LINTFLAGS", _CS_LFS64_LINTFLAGS, CONFSTR },
212 /* Programming environments. */
213 { "_XBS5_WIDTH_RESTRICTED_ENVS", _CS_V5_WIDTH_RESTRICTED_ENVS, CONFSTR },
214 { "XBS5_WIDTH_RESTRICTED_ENVS", _CS_V5_WIDTH_RESTRICTED_ENVS, CONFSTR },
216 { "_XBS5_ILP32_OFF32", _SC_XBS5_ILP32_OFF32, SYSCONF },
217 { "XBS5_ILP32_OFF32_CFLAGS", _CS_XBS5_ILP32_OFF32_CFLAGS, CONFSTR },
218 { "XBS5_ILP32_OFF32_LDFLAGS", _CS_XBS5_ILP32_OFF32_LDFLAGS, CONFSTR },
219 { "XBS5_ILP32_OFF32_LIBS", _CS_XBS5_ILP32_OFF32_LIBS, CONFSTR },
220 { "XBS5_ILP32_OFF32_LINTFLAGS", _CS_XBS5_ILP32_OFF32_LINTFLAGS, CONFSTR },
222 { "_XBS5_ILP32_OFFBIG", _SC_XBS5_ILP32_OFFBIG, SYSCONF },
223 { "XBS5_ILP32_OFFBIG_CFLAGS", _CS_XBS5_ILP32_OFFBIG_CFLAGS, CONFSTR },
224 { "XBS5_ILP32_OFFBIG_LDFLAGS", _CS_XBS5_ILP32_OFFBIG_LDFLAGS, CONFSTR },
225 { "XBS5_ILP32_OFFBIG_LIBS", _CS_XBS5_ILP32_OFFBIG_LIBS, CONFSTR },
226 { "XBS5_ILP32_OFFBIG_LINTFLAGS", _CS_XBS5_ILP32_OFFBIG_LINTFLAGS, CONFSTR },
228 { "_XBS5_LP64_OFF64", _SC_XBS5_LP64_OFF64, SYSCONF },
229 { "XBS5_LP64_OFF64_CFLAGS", _CS_XBS5_LP64_OFF64_CFLAGS, CONFSTR },
230 { "XBS5_LP64_OFF64_LDFLAGS", _CS_XBS5_LP64_OFF64_LDFLAGS, CONFSTR },
231 { "XBS5_LP64_OFF64_LIBS", _CS_XBS5_LP64_OFF64_LIBS, CONFSTR },
232 { "XBS5_LP64_OFF64_LINTFLAGS", _CS_XBS5_LP64_OFF64_LINTFLAGS, CONFSTR },
234 { "_XBS5_LPBIG_OFFBIG", _SC_XBS5_LPBIG_OFFBIG, SYSCONF },
235 { "XBS5_LPBIG_OFFBIG_CFLAGS", _CS_XBS5_LPBIG_OFFBIG_CFLAGS, CONFSTR },
236 { "XBS5_LPBIG_OFFBIG_LDFLAGS", _CS_XBS5_LPBIG_OFFBIG_LDFLAGS, CONFSTR },
237 { "XBS5_LPBIG_OFFBIG_LIBS", _CS_XBS5_LPBIG_OFFBIG_LIBS, CONFSTR },
238 { "XBS5_LPBIG_OFFBIG_LINTFLAGS", _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, CONFSTR },
240 { "_POSIX_V6_ILP32_OFF32", _SC_V6_ILP32_OFF32, SYSCONF },
241 { "POSIX_V6_ILP32_OFF32_CFLAGS", _CS_POSIX_V6_ILP32_OFF32_CFLAGS, CONFSTR },
242 { "POSIX_V6_ILP32_OFF32_LDFLAGS", _CS_POSIX_V6_ILP32_OFF32_LDFLAGS, CONFSTR },
243 { "POSIX_V6_ILP32_OFF32_LIBS", _CS_POSIX_V6_ILP32_OFF32_LIBS, CONFSTR },
244 { "POSIX_V6_ILP32_OFF32_LINTFLAGS", _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS, CONFSTR },
246 { "_POSIX_V6_WIDTH_RESTRICTED_ENVS", _CS_V6_WIDTH_RESTRICTED_ENVS, CONFSTR },
247 { "POSIX_V6_WIDTH_RESTRICTED_ENVS", _CS_V6_WIDTH_RESTRICTED_ENVS, CONFSTR },
249 { "_POSIX_V6_ILP32_OFFBIG", _SC_V6_ILP32_OFFBIG, SYSCONF },
250 { "POSIX_V6_ILP32_OFFBIG_CFLAGS", _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS, CONFSTR },
251 { "POSIX_V6_ILP32_OFFBIG_LDFLAGS", _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS, CONFSTR },
252 { "POSIX_V6_ILP32_OFFBIG_LIBS", _CS_POSIX_V6_ILP32_OFFBIG_LIBS, CONFSTR },
253 { "POSIX_V6_ILP32_OFFBIG_LINTFLAGS", _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS, CONFSTR },
255 { "_POSIX_V6_LP64_OFF64", _SC_V6_LP64_OFF64, SYSCONF },
256 { "POSIX_V6_LP64_OFF64_CFLAGS", _CS_POSIX_V6_LP64_OFF64_CFLAGS, CONFSTR },
257 { "POSIX_V6_LP64_OFF64_LDFLAGS", _CS_POSIX_V6_LP64_OFF64_LDFLAGS, CONFSTR },
258 { "POSIX_V6_LP64_OFF64_LIBS", _CS_POSIX_V6_LP64_OFF64_LIBS, CONFSTR },
259 { "POSIX_V6_LP64_OFF64_LINTFLAGS", _CS_POSIX_V6_LP64_OFF64_LINTFLAGS, CONFSTR },
261 { "_POSIX_V6_LPBIG_OFFBIG", _SC_V6_LPBIG_OFFBIG, SYSCONF },
262 { "POSIX_V6_LPBIG_OFFBIG_CFLAGS", _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS, CONFSTR },
263 { "POSIX_V6_LPBIG_OFFBIG_LDFLAGS", _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS, CONFSTR },
264 { "POSIX_V6_LPBIG_OFFBIG_LIBS", _CS_POSIX_V6_LPBIG_OFFBIG_LIBS, CONFSTR },
265 { "POSIX_V6_LPBIG_OFFBIG_LINTFLAGS", _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS, CONFSTR },
267 { "_POSIX_V7_ILP32_OFF32", _SC_V7_ILP32_OFF32, SYSCONF },
268 { "POSIX_V7_ILP32_OFF32_CFLAGS", _CS_POSIX_V7_ILP32_OFF32_CFLAGS, CONFSTR },
269 { "POSIX_V7_ILP32_OFF32_LDFLAGS", _CS_POSIX_V7_ILP32_OFF32_LDFLAGS, CONFSTR },
270 { "POSIX_V7_ILP32_OFF32_LIBS", _CS_POSIX_V7_ILP32_OFF32_LIBS, CONFSTR },
271 { "POSIX_V7_ILP32_OFF32_LINTFLAGS", _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS, CONFSTR },
273 { "_POSIX_V7_WIDTH_RESTRICTED_ENVS", _CS_V7_WIDTH_RESTRICTED_ENVS, CONFSTR },
274 { "POSIX_V7_WIDTH_RESTRICTED_ENVS", _CS_V7_WIDTH_RESTRICTED_ENVS, CONFSTR },
276 { "_POSIX_V7_ILP32_OFFBIG", _SC_V7_ILP32_OFFBIG, SYSCONF },
277 { "POSIX_V7_ILP32_OFFBIG_CFLAGS", _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS, CONFSTR },
278 { "POSIX_V7_ILP32_OFFBIG_LDFLAGS", _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS, CONFSTR },
279 { "POSIX_V7_ILP32_OFFBIG_LIBS", _CS_POSIX_V7_ILP32_OFFBIG_LIBS, CONFSTR },
280 { "POSIX_V7_ILP32_OFFBIG_LINTFLAGS", _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS, CONFSTR },
282 { "_POSIX_V7_LP64_OFF64", _SC_V7_LP64_OFF64, SYSCONF },
283 { "POSIX_V7_LP64_OFF64_CFLAGS", _CS_POSIX_V7_LP64_OFF64_CFLAGS, CONFSTR },
284 { "POSIX_V7_LP64_OFF64_LDFLAGS", _CS_POSIX_V7_LP64_OFF64_LDFLAGS, CONFSTR },
285 { "POSIX_V7_LP64_OFF64_LIBS", _CS_POSIX_V7_LP64_OFF64_LIBS, CONFSTR },
286 { "POSIX_V7_LP64_OFF64_LINTFLAGS", _CS_POSIX_V7_LP64_OFF64_LINTFLAGS, CONFSTR },
288 { "_POSIX_V7_LPBIG_OFFBIG", _SC_V7_LPBIG_OFFBIG, SYSCONF },
289 { "POSIX_V7_LPBIG_OFFBIG_CFLAGS", _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS, CONFSTR },
290 { "POSIX_V7_LPBIG_OFFBIG_LDFLAGS", _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS, CONFSTR },
291 { "POSIX_V7_LPBIG_OFFBIG_LIBS", _CS_POSIX_V7_LPBIG_OFFBIG_LIBS, CONFSTR },
292 { "POSIX_V7_LPBIG_OFFBIG_LINTFLAGS", _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS, CONFSTR },
294 { "_POSIX_ADVISORY_INFO", _SC_ADVISORY_INFO, SYSCONF },
295 { "_POSIX_BARRIERS", _SC_BARRIERS, SYSCONF },
296 { "_POSIX_BASE", _SC_BASE, SYSCONF },
297 { "_POSIX_C_LANG_SUPPORT", _SC_C_LANG_SUPPORT, SYSCONF },
298 { "_POSIX_C_LANG_SUPPORT_R", _SC_C_LANG_SUPPORT_R, SYSCONF },
299 { "_POSIX_CLOCK_SELECTION", _SC_CLOCK_SELECTION, SYSCONF },
300 { "_POSIX_CPUTIME", _SC_CPUTIME, SYSCONF },
301 { "_POSIX_THREAD_CPUTIME", _SC_THREAD_CPUTIME, SYSCONF },
302 { "_POSIX_DEVICE_SPECIFIC", _SC_DEVICE_SPECIFIC, SYSCONF },
303 { "_POSIX_DEVICE_SPECIFIC_R", _SC_DEVICE_SPECIFIC_R, SYSCONF },
304 { "_POSIX_FD_MGMT", _SC_FD_MGMT, SYSCONF },
305 { "_POSIX_FIFO", _SC_FIFO, SYSCONF },
306 { "_POSIX_PIPE", _SC_PIPE, SYSCONF },
307 { "_POSIX_FILE_ATTRIBUTES", _SC_FILE_ATTRIBUTES, SYSCONF },
308 { "_POSIX_FILE_LOCKING", _SC_FILE_LOCKING, SYSCONF },
309 { "_POSIX_FILE_SYSTEM", _SC_FILE_SYSTEM, SYSCONF },
310 { "_POSIX_MONOTONIC_CLOCK", _SC_MONOTONIC_CLOCK, SYSCONF },
311 { "_POSIX_MULTI_PROCESS", _SC_MULTI_PROCESS, SYSCONF },
312 { "_POSIX_SINGLE_PROCESS", _SC_SINGLE_PROCESS, SYSCONF },
313 { "_POSIX_NETWORKING", _SC_NETWORKING, SYSCONF },
314 { "_POSIX_READER_WRITER_LOCKS", _SC_READER_WRITER_LOCKS, SYSCONF },
315 { "_POSIX_SPIN_LOCKS", _SC_SPIN_LOCKS, SYSCONF },
316 { "_POSIX_REGEXP", _SC_REGEXP, SYSCONF },
317 { "_REGEX_VERSION", _SC_REGEX_VERSION, SYSCONF },
318 { "_POSIX_SHELL", _SC_SHELL, SYSCONF },
319 { "_POSIX_SIGNALS", _SC_SIGNALS, SYSCONF },
320 { "_POSIX_SPAWN", _SC_SPAWN, SYSCONF },
321 { "_POSIX_SPORADIC_SERVER", _SC_SPORADIC_SERVER, SYSCONF },
322 { "_POSIX_THREAD_SPORADIC_SERVER", _SC_THREAD_SPORADIC_SERVER, SYSCONF },
323 { "_POSIX_SYSTEM_DATABASE", _SC_SYSTEM_DATABASE, SYSCONF },
324 { "_POSIX_SYSTEM_DATABASE_R", _SC_SYSTEM_DATABASE_R, SYSCONF },
325 { "_POSIX_TIMEOUTS", _SC_TIMEOUTS, SYSCONF },
326 { "_POSIX_TYPED_MEMORY_OBJECTS", _SC_TYPED_MEMORY_OBJECTS, SYSCONF },
327 { "_POSIX_USER_GROUPS", _SC_USER_GROUPS, SYSCONF },
328 { "_POSIX_USER_GROUPS_R", _SC_USER_GROUPS_R, SYSCONF },
329 { "POSIX2_PBS", _SC_2_PBS, SYSCONF },
330 { "POSIX2_PBS_ACCOUNTING", _SC_2_PBS_ACCOUNTING, SYSCONF },
331 { "POSIX2_PBS_LOCATE", _SC_2_PBS_LOCATE, SYSCONF },
332 { "POSIX2_PBS_TRACK", _SC_2_PBS_TRACK, SYSCONF },
333 { "POSIX2_PBS_MESSAGE", _SC_2_PBS_MESSAGE, SYSCONF },
334 { "SYMLOOP_MAX", _SC_SYMLOOP_MAX, SYSCONF },
335 { "STREAM_MAX", _SC_STREAM_MAX, SYSCONF },
336 { "AIO_LISTIO_MAX", _SC_AIO_LISTIO_MAX, SYSCONF },
337 { "AIO_MAX", _SC_AIO_MAX, SYSCONF },
338 { "AIO_PRIO_DELTA_MAX", _SC_AIO_PRIO_DELTA_MAX, SYSCONF },
339 { "DELAYTIMER_MAX", _SC_DELAYTIMER_MAX, SYSCONF },
340 { "HOST_NAME_MAX", _SC_HOST_NAME_MAX, SYSCONF },
341 { "LOGIN_NAME_MAX", _SC_LOGIN_NAME_MAX, SYSCONF },
342 { "MQ_OPEN_MAX", _SC_MQ_OPEN_MAX, SYSCONF },
343 { "MQ_PRIO_MAX", _SC_MQ_PRIO_MAX, SYSCONF },
344 { "_POSIX_DEVICE_IO", _SC_DEVICE_IO, SYSCONF },
345 { "_POSIX_TRACE", _SC_TRACE, SYSCONF },
346 { "_POSIX_TRACE_EVENT_FILTER", _SC_TRACE_EVENT_FILTER, SYSCONF },
347 { "_POSIX_TRACE_INHERIT", _SC_TRACE_INHERIT, SYSCONF },
348 { "_POSIX_TRACE_LOG", _SC_TRACE_LOG, SYSCONF },
349 { "RTSIG_MAX", _SC_RTSIG_MAX, SYSCONF },
350 { "SEM_NSEMS_MAX", _SC_SEM_NSEMS_MAX, SYSCONF },
351 { "SEM_VALUE_MAX", _SC_SEM_VALUE_MAX, SYSCONF },
352 { "SIGQUEUE_MAX", _SC_SIGQUEUE_MAX, SYSCONF },
353 { "FILESIZEBITS", _PC_FILESIZEBITS, PATHCONF },
354 { "POSIX_ALLOC_SIZE_MIN", _PC_ALLOC_SIZE_MIN, PATHCONF },
355 { "POSIX_REC_INCR_XFER_SIZE", _PC_REC_INCR_XFER_SIZE, PATHCONF },
356 { "POSIX_REC_MAX_XFER_SIZE", _PC_REC_MAX_XFER_SIZE, PATHCONF },
357 { "POSIX_REC_MIN_XFER_SIZE", _PC_REC_MIN_XFER_SIZE, PATHCONF },
358 { "POSIX_REC_XFER_ALIGN", _PC_REC_XFER_ALIGN, PATHCONF },
359 { "SYMLINK_MAX", _PC_SYMLINK_MAX, PATHCONF },
360 { "GNU_LIBC_VERSION", _CS_GNU_LIBC_VERSION, CONFSTR },
361 { "GNU_LIBPTHREAD_VERSION", _CS_GNU_LIBPTHREAD_VERSION, CONFSTR },
362 { "POSIX2_SYMLINKS", _PC_2_SYMLINKS, PATHCONF },
364 { "LEVEL1_ICACHE_SIZE", _SC_LEVEL1_ICACHE_SIZE, SYSCONF },
365 { "LEVEL1_ICACHE_ASSOC", _SC_LEVEL1_ICACHE_ASSOC, SYSCONF },
366 { "LEVEL1_ICACHE_LINESIZE", _SC_LEVEL1_ICACHE_LINESIZE, SYSCONF },
367 { "LEVEL1_DCACHE_SIZE", _SC_LEVEL1_DCACHE_SIZE, SYSCONF },
368 { "LEVEL1_DCACHE_ASSOC", _SC_LEVEL1_DCACHE_ASSOC, SYSCONF },
369 { "LEVEL1_DCACHE_LINESIZE", _SC_LEVEL1_DCACHE_LINESIZE, SYSCONF },
370 { "LEVEL2_CACHE_SIZE", _SC_LEVEL2_CACHE_SIZE, SYSCONF },
371 { "LEVEL2_CACHE_ASSOC", _SC_LEVEL2_CACHE_ASSOC, SYSCONF },
372 { "LEVEL2_CACHE_LINESIZE", _SC_LEVEL2_CACHE_LINESIZE, SYSCONF },
373 { "LEVEL3_CACHE_SIZE", _SC_LEVEL3_CACHE_SIZE, SYSCONF },
374 { "LEVEL3_CACHE_ASSOC", _SC_LEVEL3_CACHE_ASSOC, SYSCONF },
375 { "LEVEL3_CACHE_LINESIZE", _SC_LEVEL3_CACHE_LINESIZE, SYSCONF },
376 { "LEVEL4_CACHE_SIZE", _SC_LEVEL4_CACHE_SIZE, SYSCONF },
377 { "LEVEL4_CACHE_ASSOC", _SC_LEVEL4_CACHE_ASSOC, SYSCONF },
378 { "LEVEL4_CACHE_LINESIZE", _SC_LEVEL4_CACHE_LINESIZE, SYSCONF },
380 { "IPV6", _SC_IPV6, SYSCONF },
381 { "RAW_SOCKETS", _SC_RAW_SOCKETS, SYSCONF },
383 { "_POSIX_IPV6", _SC_IPV6, SYSCONF },
384 { "_POSIX_RAW_SOCKETS", _SC_RAW_SOCKETS, SYSCONF },
386 { NULL, 0, SYSCONF }
390 static const struct { const char *name; int num; } specs[] =
392 { "XBS5_ILP32_OFF32", _SC_XBS5_ILP32_OFF32 },
393 { "XBS5_ILP32_OFFBIG", _SC_XBS5_ILP32_OFFBIG },
394 { "XBS5_LP64_OFF64", _SC_XBS5_LP64_OFF64 },
395 { "XBS5_LPBIG_OFFBIG", _SC_XBS5_LPBIG_OFFBIG },
396 { "POSIX_V6_ILP32_OFF32", _SC_V6_ILP32_OFF32 },
397 { "POSIX_V6_ILP32_OFFBIG", _SC_V6_ILP32_OFFBIG },
398 { "POSIX_V6_LP64_OFF64", _SC_V6_LP64_OFF64 },
399 { "POSIX_V6_LPBIG_OFFBIG", _SC_V6_LPBIG_OFFBIG },
400 { "POSIX_V7_ILP32_OFF32", _SC_V7_ILP32_OFF32 },
401 { "POSIX_V7_ILP32_OFFBIG", _SC_V7_ILP32_OFFBIG },
402 { "POSIX_V7_LP64_OFF64", _SC_V7_LP64_OFF64 },
403 { "POSIX_V7_LPBIG_OFFBIG", _SC_V7_LPBIG_OFFBIG },
405 static const int nspecs = sizeof (specs) / sizeof (specs[0]);
407 extern const char *__progname;
410 static void
411 usage (void)
413 fprintf (stderr,
414 _("Usage: %s [-v specification] variable_name [pathname]\n"),
415 __progname);
416 fprintf (stderr,
417 _(" %s -a [pathname]\n"), __progname);
418 exit (2);
422 static void
423 print_all (const char *path)
425 const struct conf *c;
426 size_t clen;
427 long int value;
428 char *cvalue;
429 for (c = vars; c->name != NULL; ++c) {
430 printf("%-35s", c->name);
431 switch (c->call) {
432 case PATHCONF:
433 value = pathconf (path, c->call_name);
434 if (value != -1) {
435 printf("%ld", value);
437 printf("\n");
438 break;
439 case SYSCONF:
440 value = sysconf (c->call_name);
441 if (value == -1l) {
442 if (c->call_name == _SC_UINT_MAX
443 || c->call_name == _SC_ULONG_MAX)
444 printf ("%lu", value);
446 else {
447 printf ("%ld", value);
449 printf ("\n");
450 break;
451 case CONFSTR:
452 clen = confstr (c->call_name, (char *) NULL, 0);
453 cvalue = (char *) malloc (clen);
454 if (cvalue == NULL)
455 error (3, 0, _("memory exhausted"));
456 if (confstr (c->call_name, cvalue, clen) != clen)
457 error (3, errno, "confstr");
458 printf ("%.*s\n", (int) clen, cvalue);
459 free (cvalue);
460 break;
463 exit (0);
467 main (int argc, char *argv[])
469 const struct conf *c;
471 /* Set locale. Do not set LC_ALL because the other categories must
472 not be affected (according to POSIX.2). */
473 setlocale (LC_CTYPE, "");
474 setlocale (LC_MESSAGES, "");
476 /* Initialize the message catalog. */
477 textdomain (PACKAGE);
479 if (argc > 1 && strcmp (argv[1], "--version") == 0)
481 printf ("getconf %s%s\n", PKGVERSION, VERSION);
482 printf (gettext ("\
483 Copyright (C) %s Free Software Foundation, Inc.\n\
484 This is free software; see the source for copying conditions. There is NO\n\
485 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
486 "), "2014");
487 printf (gettext ("Written by %s.\n"), "Roland McGrath");
488 return 0;
491 if (argc > 1 && strcmp (argv[1], "--help") == 0)
493 printf (gettext ("\
494 Usage: getconf [-v SPEC] VAR\n\
495 or: getconf [-v SPEC] PATH_VAR PATH\n\
497 Get the configuration value for variable VAR, or for variable PATH_VAR\n\
498 for path PATH. If SPEC is given, give values for compilation\n\
499 environment SPEC.\n\n"));
500 printf (gettext ("For bug reporting instructions, please see:\n\
501 %s.\n"), REPORT_BUGS_TO);
502 return 0;
505 const char *getconf_dir = getenv ("GETCONF_DIR") ?: GETCONF_DIR;
506 size_t getconf_dirlen = strlen (getconf_dir);
508 const char *spec = NULL;
509 char buf[sizeof "POSIX_V6_LPBIG_OFFBIG"];
510 char *argv0 = argv[0];
511 if (argc > 1 && strncmp (argv[1], "-v", 2) == 0)
513 if (argv[1][2] == '\0')
515 if (argc < 3)
516 usage ();
518 spec = argv[2];
519 argv += 2;
520 argc -= 2;
522 else
524 spec = &argv[1][2];
525 argv += 1;
526 argc += 1;
529 else
531 char default_name[getconf_dirlen + sizeof "/default"];
532 memcpy (mempcpy (default_name, getconf_dir, getconf_dirlen),
533 "/default", sizeof "/default");
534 int len = readlink (default_name, buf, sizeof buf - 1);
535 if (len > 0)
537 buf[len] = '\0';
538 spec = buf;
542 /* Check for the specifications we know. */
543 if (spec != NULL)
545 int i;
546 for (i = 0; i < nspecs; ++i)
547 if (strcmp (spec, specs[i].name) == 0)
548 break;
550 if (i == nspecs)
551 error (2, 0, _("unknown specification \"%s\""), spec);
553 switch (specs[i].num)
555 #ifndef _XBS5_ILP32_OFF32
556 case _SC_XBS5_ILP32_OFF32:
557 #endif
558 #ifndef _XBS5_ILP32_OFFBIG
559 case _SC_XBS5_ILP32_OFFBIG:
560 #endif
561 #ifndef _XBS5_LP64_OFF64
562 case _SC_XBS5_LP64_OFF64:
563 #endif
564 #ifndef _XBS5_LPBIG_OFFBIG
565 case _SC_XBS5_LPBIG_OFFBIG:
566 #endif
567 #ifndef _POSIX_V6_ILP32_OFF32
568 case _SC_V6_ILP32_OFF32:
569 #endif
570 #ifndef _POSIX_V6_ILP32_OFFBIG
571 case _SC_V6_ILP32_OFFBIG:
572 #endif
573 #ifndef _POSIX_V6_LP64_OFF64
574 case _SC_V6_LP64_OFF64:
575 #endif
576 #ifndef _POSIX_V6_LPBIG_OFFBIG
577 case _SC_V6_LPBIG_OFFBIG:
578 #endif
579 #ifndef _POSIX_V7_ILP32_OFF32
580 case _SC_V7_ILP32_OFF32:
581 #endif
582 #ifndef _POSIX_V7_ILP32_OFFBIG
583 case _SC_V7_ILP32_OFFBIG:
584 #endif
585 #ifndef _POSIX_V7_LP64_OFF64
586 case _SC_V7_LP64_OFF64:
587 #endif
588 #ifndef _POSIX_V7_LPBIG_OFFBIG
589 case _SC_V7_LPBIG_OFFBIG:
590 #endif
592 const char *args[argc + 3];
593 size_t spec_len = strlen (spec);
594 char getconf_name[getconf_dirlen + 1 + spec_len + 1];
595 memcpy (mempcpy (mempcpy (getconf_name, getconf_dir,
596 getconf_dirlen),
597 "/", 1), spec, spec_len + 1);
598 args[0] = argv0;
599 args[1] = "-v";
600 args[2] = spec;
601 memcpy (&args[3], &argv[1], argc * sizeof (argv[1]));
602 execv (getconf_name, (char * const *) args);
603 error (4, errno, _("Couldn't execute %s"), getconf_name);
605 default:
606 break;
610 if (argc > 1 && strcmp (argv[1], "-a") == 0)
612 if (argc == 2)
613 print_all ("/");
614 else if (argc == 3)
615 print_all (argv[2]);
616 else
617 usage ();
620 int ai = 1;
621 if (argc > ai && strcmp (argv[ai], "--") == 0)
622 ++ai;
624 if (argc - ai < 1 || argc - ai > 2)
625 usage ();
627 for (c = vars; c->name != NULL; ++c)
628 if (strcmp (c->name, argv[ai]) == 0
629 || (strncmp (c->name, "_POSIX_", 7) == 0
630 && strcmp (c->name + 7, argv[ai]) == 0))
632 long int value;
633 size_t clen;
634 char *cvalue;
635 switch (c->call)
637 case PATHCONF:
638 if (argc - ai < 2)
639 usage ();
640 errno = 0;
641 value = pathconf (argv[ai + 1], c->call_name);
642 if (value == -1)
644 if (errno)
645 error (3, errno, "pathconf: %s", argv[ai + 1]);
646 else
647 puts (_("undefined"));
649 else
650 printf ("%ld\n", value);
651 exit (0);
653 case SYSCONF:
654 if (argc - ai > 1)
655 usage ();
656 value = sysconf (c->call_name);
657 if (value == -1l)
659 if (c->call_name == _SC_UINT_MAX
660 || c->call_name == _SC_ULONG_MAX)
661 printf ("%lu\n", value);
662 else
663 puts (_("undefined"));
665 else
666 printf ("%ld\n", value);
667 exit (0);
669 case CONFSTR:
670 if (argc - ai > 1)
671 usage ();
672 clen = confstr (c->call_name, (char *) NULL, 0);
673 cvalue = (char *) malloc (clen);
674 if (cvalue == NULL)
675 error (3, 0, _("memory exhausted"));
677 if (confstr (c->call_name, cvalue, clen) != clen)
678 error (3, errno, "confstr");
680 printf ("%.*s\n", (int) clen, cvalue);
681 exit (0);
685 error (2, 0, _("Unrecognized variable `%s'"), argv[ai]);
686 /* NOTREACHED */
687 return 2;