1 /* Copyright (C) 1991-2012 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 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.
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.
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 <http://www.gnu.org/licenses/>. */
23 #include "../version.h"
25 /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
26 of BUF with the value corresponding to NAME and zero-terminate BUF.
27 Return the number of bytes required to hold NAME's entire value. */
29 confstr (name, buf, len)
34 const char *string = "";
35 size_t string_len = 1;
36 char restenvs[4 * sizeof "POSIX_V7_LPBIG_OFFBIG"];
37 char restenvs[4 * sizeof "POSIX_V6_LPBIG_OFFBIG"];
38 char restenvs[4 * sizeof "XBS5_LPBIG_OFFBIG"];
44 static const char cs_path[] = CS_PATH;
46 string_len = sizeof (cs_path);
50 case _CS_V7_WIDTH_RESTRICTED_ENVS:
51 /* We have to return a newline-separated list of named of
52 programming environements in which the widths of blksize_t,
53 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
54 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
55 wint_t types are no greater than the width of type long.
57 Currently this means all environment which the system allows. */
59 #ifndef _POSIX_V7_ILP32_OFF32
60 if (__sysconf (_SC_V7_ILP32_OFF32) > 0)
62 #if !defined _POSIX_V7_ILP32_OFF32 || _POSIX_V7_ILP32_OFF32 > 0
64 memcpy (restenvs + string_len, "POSIX_V7_ILP32_OFF32",
65 sizeof "POSIX_V7_ILP32_OFF32" - 1);
66 string_len += sizeof "POSIX_V7_ILP32_OFF32" - 1;
69 #ifndef _POSIX_V7_ILP32_OFFBIG
70 if (__sysconf (_SC_V7_ILP32_OFFBIG) > 0)
72 #if !defined _POSIX_V7_ILP32_OFFBIG || _POSIX_V7_ILP32_OFFBIG > 0
75 restenvs[string_len++] = '\n';
76 memcpy (restenvs + string_len, "POSIX_V7_ILP32_OFFBIG",
77 sizeof "POSIX_V7_ILP32_OFFBIG" - 1);
78 string_len += sizeof "POSIX_V7_ILP32_OFFBIG" - 1;
81 #ifndef _POSIX_V7_LP64_OFF64
82 if (__sysconf (_SC_V7_LP64_OFF64) > 0)
84 #if !defined _POSIX_V7_LP64_OFF64 || _POSIX_V7_LP64_OFF64 > 0
87 restenvs[string_len++] = '\n';
88 memcpy (restenvs + string_len, "POSIX_V7_LP64_OFF64",
89 sizeof "POSIX_V7_LP64_OFF64" - 1);
90 string_len += sizeof "POSIX_V7_LP64_OFF64" - 1;
93 #ifndef _POSIX_V7_LPBIG_OFFBIG
94 if (__sysconf (_SC_V7_LPBIG_OFFBIG) > 0)
96 #if !defined _POSIX_V7_LPBIG_OFFBIG || _POSIX_V7_LPBIG_OFFBIG > 0
99 restenvs[string_len++] = '\n';
100 memcpy (restenvs + string_len, "POSIX_V7_LPBIG_OFFBIG",
101 sizeof "POSIX_V7_LPBIG_OFFBIG" - 1);
102 string_len += sizeof "POSIX_V7_LPBIG_OFFBIG" - 1;
105 restenvs[string_len++] = '\0';
109 case _CS_V6_WIDTH_RESTRICTED_ENVS:
110 /* We have to return a newline-separated list of named of
111 programming environements in which the widths of blksize_t,
112 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
113 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
114 wint_t types are no greater than the width of type long.
116 Currently this means all environment which the system allows. */
118 #ifndef _POSIX_V6_ILP32_OFF32
119 if (__sysconf (_SC_V6_ILP32_OFF32) > 0)
121 #if !defined _POSIX_V6_ILP32_OFF32 || _POSIX_V6_ILP32_OFF32 > 0
123 memcpy (restenvs + string_len, "POSIX_V6_ILP32_OFF32",
124 sizeof "POSIX_V6_ILP32_OFF32" - 1);
125 string_len += sizeof "POSIX_V6_ILP32_OFF32" - 1;
128 #ifndef _POSIX_V6_ILP32_OFFBIG
129 if (__sysconf (_SC_V6_ILP32_OFFBIG) > 0)
131 #if !defined _POSIX_V6_ILP32_OFFBIG || _POSIX_V6_ILP32_OFFBIG > 0
134 restenvs[string_len++] = '\n';
135 memcpy (restenvs + string_len, "POSIX_V6_ILP32_OFFBIG",
136 sizeof "POSIX_V6_ILP32_OFFBIG" - 1);
137 string_len += sizeof "POSIX_V6_ILP32_OFFBIG" - 1;
140 #ifndef _POSIX_V6_LP64_OFF64
141 if (__sysconf (_SC_V6_LP64_OFF64) > 0)
143 #if !defined _POSIX_V6_LP64_OFF64 || _POSIX_V6_LP64_OFF64 > 0
146 restenvs[string_len++] = '\n';
147 memcpy (restenvs + string_len, "POSIX_V6_LP64_OFF64",
148 sizeof "POSIX_V6_LP64_OFF64" - 1);
149 string_len += sizeof "POSIX_V6_LP64_OFF64" - 1;
152 #ifndef _POSIX_V6_LPBIG_OFFBIG
153 if (__sysconf (_SC_V6_LPBIG_OFFBIG) > 0)
155 #if !defined _POSIX_V6_LPBIG_OFFBIG || _POSIX_V6_LPBIG_OFFBIG > 0
158 restenvs[string_len++] = '\n';
159 memcpy (restenvs + string_len, "POSIX_V6_LPBIG_OFFBIG",
160 sizeof "POSIX_V6_LPBIG_OFFBIG" - 1);
161 string_len += sizeof "POSIX_V6_LPBIG_OFFBIG" - 1;
164 restenvs[string_len++] = '\0';
168 case _CS_V5_WIDTH_RESTRICTED_ENVS:
169 /* We have to return a newline-separated list of named of
170 programming environements in which the widths of blksize_t,
171 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
172 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
173 wint_t types are no greater than the width of type long.
175 Currently this means all environment which the system allows. */
177 #ifndef _XBS5_ILP32_OFF32
178 if (__sysconf (_SC_XBS5_ILP32_OFF32) > 0)
180 #if !defined _XBS5_ILP32_OFF32 || _XBS5_ILP32_OFF32 > 0
182 memcpy (restenvs + string_len, "XBS5_ILP32_OFF32",
183 sizeof "XBS5_ILP32_OFF32" - 1);
184 string_len += sizeof "XBS5_ILP32_OFF32" - 1;
187 #ifndef _XBS5_ILP32_OFFBIG
188 if (__sysconf (_SC_XBS5_ILP32_OFFBIG) > 0)
190 #if !defined _XBS5_ILP32_OFFBIG || _XBS5_ILP32_OFFBIG > 0
193 restenvs[string_len++] = '\n';
194 memcpy (restenvs + string_len, "XBS5_ILP32_OFFBIG",
195 sizeof "XBS5_ILP32_OFFBIG" - 1);
196 string_len += sizeof "XBS5_ILP32_OFFBIG" - 1;
199 #ifndef _XBS5_LP64_OFF64
200 if (__sysconf (_SC_XBS5_LP64_OFF64) > 0)
202 #if !defined _XBS5_LP64_OFF64 || _XBS5_LP64_OFF64 > 0
205 restenvs[string_len++] = '\n';
206 memcpy (restenvs + string_len, "XBS5_LP64_OFF64",
207 sizeof "XBS5_LP64_OFF64" - 1);
208 string_len += sizeof "XBS5_LP64_OFF64" - 1;
211 #ifndef _XBS5_LPBIG_OFFBIG
212 if (__sysconf (_SC_XBS5_LPBIG_OFFBIG) > 0)
214 #if !defined _XBS5_LPBIG_OFFBIG || _XBS5_LPBIG_OFFBIG > 0
217 restenvs[string_len++] = '\n';
218 memcpy (restenvs + string_len, "XBS5_LPBIG_OFFBIG",
219 sizeof "XBS5_LPBIG_OFFBIG" - 1);
220 string_len += sizeof "XBS5_LPBIG_OFFBIG" - 1;
223 restenvs[string_len++] = '\0';
227 case _CS_XBS5_ILP32_OFF32_CFLAGS:
228 case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
229 case _CS_POSIX_V7_ILP32_OFF32_CFLAGS:
230 #ifdef __ILP32_OFF32_CFLAGS
231 # if _POSIX_V7_ILP32_OFF32 == -1
232 # error "__ILP32_OFF32_CFLAGS should not be defined"
233 # elif !defined _POSIX_V7_ILP32_OFF32
234 if (__sysconf (_SC_V7_ILP32_OFF32) < 0)
237 string = __ILP32_OFF32_CFLAGS;
238 string_len = sizeof (__ILP32_OFF32_CFLAGS);
242 case _CS_XBS5_ILP32_OFFBIG_CFLAGS:
243 case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
244 case _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS:
245 #ifdef __ILP32_OFFBIG_CFLAGS
246 # if _POSIX_V7_ILP32_OFFBIG == -1
247 # error "__ILP32_OFFBIG_CFLAGS should not be defined"
248 # elif !defined _POSIX_V7_ILP32_OFFBIG
249 if (__sysconf (_SC_V7_ILP32_OFFBIG) < 0)
252 string = __ILP32_OFFBIG_CFLAGS;
253 string_len = sizeof (__ILP32_OFFBIG_CFLAGS);
257 case _CS_XBS5_LP64_OFF64_CFLAGS:
258 case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
259 case _CS_POSIX_V7_LP64_OFF64_CFLAGS:
260 #ifdef __LP64_OFF64_CFLAGS
261 # if _POSIX_V7_LP64_OFF64 == -1
262 # error "__LP64_OFF64_CFLAGS should not be defined"
263 # elif !defined _POSIX_V7_LP64_OFF64
264 if (__sysconf (_SC_V7_LP64_OFF64) < 0)
267 string = __LP64_OFF64_CFLAGS;
268 string_len = sizeof (__LP64_OFF64_CFLAGS);
272 case _CS_XBS5_ILP32_OFF32_LDFLAGS:
273 case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
274 case _CS_POSIX_V7_ILP32_OFF32_LDFLAGS:
275 #ifdef __ILP32_OFF32_LDFLAGS
276 # if _POSIX_V7_ILP32_OFF32 == -1
277 # error "__ILP32_OFF32_LDFLAGS should not be defined"
278 # elif !defined _POSIX_V7_ILP32_OFF32
279 if (__sysconf (_SC_V7_ILP32_OFF32) < 0)
282 string = __ILP32_OFF32_LDFLAGS;
283 string_len = sizeof (__ILP32_OFF32_LDFLAGS);
287 case _CS_XBS5_ILP32_OFFBIG_LDFLAGS:
288 case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
289 case _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS:
290 #ifdef __ILP32_OFFBIG_LDFLAGS
291 # if _POSIX_V7_ILP32_OFFBIG == -1
292 # error "__ILP32_OFFBIG_LDFLAGS should not be defined"
293 # elif !defined _POSIX_V7_ILP32_OFFBIG
294 if (__sysconf (_SC_V7_ILP32_OFFBIG) < 0)
297 string = __ILP32_OFFBIG_LDFLAGS;
298 string_len = sizeof (__ILP32_OFFBIG_LDFLAGS);
302 case _CS_XBS5_LP64_OFF64_LDFLAGS:
303 case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
304 case _CS_POSIX_V7_LP64_OFF64_LDFLAGS:
305 #ifdef __LP64_OFF64_LDFLAGS
306 # if _POSIX_V7_LP64_OFF64 == -1
307 # error "__LP64_OFF64_LDFLAGS should not be defined"
308 # elif !defined _POSIX_V7_LP64_OFF64
309 if (__sysconf (_SC_V7_LP64_OFF64) < 0)
312 string = __LP64_OFF64_LDFLAGS;
313 string_len = sizeof (__LP64_OFF64_LDFLAGS);
318 case _CS_LFS_LINTFLAGS:
319 #if _POSIX_V6_ILP32_OFF32 == 1 && _POSIX_V6_ILP32_OFFBIG == 1
320 # define __LFS_CFLAGS "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
321 /* Signal that we want the new ABI. */
322 string = __LFS_CFLAGS;
323 string_len = sizeof (__LFS_CFLAGS);
327 case _CS_LFS_LDFLAGS:
329 /* No special libraries or linker flags needed. */
332 case _CS_LFS64_CFLAGS:
333 case _CS_LFS64_LINTFLAGS:
334 #define __LFS64_CFLAGS "-D_LARGEFILE64_SOURCE"
335 string = __LFS64_CFLAGS;
336 string_len = sizeof (__LFS64_CFLAGS);
339 case _CS_LFS64_LDFLAGS:
341 /* No special libraries or linker flags needed. */
344 case _CS_XBS5_ILP32_OFF32_LIBS:
345 case _CS_XBS5_ILP32_OFF32_LINTFLAGS:
346 case _CS_XBS5_ILP32_OFFBIG_LIBS:
347 case _CS_XBS5_ILP32_OFFBIG_LINTFLAGS:
348 case _CS_XBS5_LP64_OFF64_LIBS:
349 case _CS_XBS5_LP64_OFF64_LINTFLAGS:
350 case _CS_XBS5_LPBIG_OFFBIG_CFLAGS:
351 case _CS_XBS5_LPBIG_OFFBIG_LDFLAGS:
352 case _CS_XBS5_LPBIG_OFFBIG_LIBS:
353 case _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS:
355 case _CS_POSIX_V6_ILP32_OFF32_LIBS:
356 case _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS:
357 case _CS_POSIX_V6_ILP32_OFFBIG_LIBS:
358 case _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS:
359 case _CS_POSIX_V6_LP64_OFF64_LIBS:
360 case _CS_POSIX_V6_LP64_OFF64_LINTFLAGS:
361 case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS:
362 case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS:
363 case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS:
364 case _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS:
366 case _CS_POSIX_V7_ILP32_OFF32_LIBS:
367 case _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS:
368 case _CS_POSIX_V7_ILP32_OFFBIG_LIBS:
369 case _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS:
370 case _CS_POSIX_V7_LP64_OFF64_LIBS:
371 case _CS_POSIX_V7_LP64_OFF64_LINTFLAGS:
372 case _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS:
373 case _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS:
374 case _CS_POSIX_V7_LPBIG_OFFBIG_LIBS:
375 case _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS:
376 /* GNU libc does not require special actions to use LFS functions. */
379 case _CS_GNU_LIBC_VERSION:
380 string = "glibc " VERSION;
381 string_len = sizeof ("glibc " VERSION);
384 case _CS_GNU_LIBPTHREAD_VERSION:
385 #ifdef LIBPTHREAD_VERSION
386 string = LIBPTHREAD_VERSION;
387 string_len = sizeof LIBPTHREAD_VERSION;
390 /* No thread library. */
391 __set_errno (EINVAL);
397 /* Maybe something else is needed in future. */
398 string = "POSIXLY_CORRECT=1";
399 string_len = sizeof ("POSIXLY_CORRECT=1");
403 __set_errno (EINVAL);
407 if (len > 0 && buf != NULL)
409 if (string_len <= len)
410 memcpy (buf, string, string_len);
413 memcpy (buf, string, len - 1);
419 libc_hidden_def (confstr)