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;
37 /* Note that this buffer must be large enough for the longest strings
39 char restenvs
[4 * sizeof "POSIX_V7_LPBIG_OFFBIG"];
45 static const char cs_path
[] = CS_PATH
;
47 string_len
= sizeof (cs_path
);
51 case _CS_V7_WIDTH_RESTRICTED_ENVS
:
52 /* We have to return a newline-separated list of named of
53 programming environements in which the widths of blksize_t,
54 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
55 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
56 wint_t types are no greater than the width of type long.
58 Currently this means all environment which the system allows. */
60 #ifndef _POSIX_V7_ILP32_OFF32
61 if (__sysconf (_SC_V7_ILP32_OFF32
) > 0)
63 #if !defined _POSIX_V7_ILP32_OFF32 || _POSIX_V7_ILP32_OFF32 > 0
65 memcpy (restenvs
+ string_len
, "POSIX_V7_ILP32_OFF32",
66 sizeof "POSIX_V7_ILP32_OFF32" - 1);
67 string_len
+= sizeof "POSIX_V7_ILP32_OFF32" - 1;
70 #ifndef _POSIX_V7_ILP32_OFFBIG
71 if (__sysconf (_SC_V7_ILP32_OFFBIG
) > 0)
73 #if !defined _POSIX_V7_ILP32_OFFBIG || _POSIX_V7_ILP32_OFFBIG > 0
76 restenvs
[string_len
++] = '\n';
77 memcpy (restenvs
+ string_len
, "POSIX_V7_ILP32_OFFBIG",
78 sizeof "POSIX_V7_ILP32_OFFBIG" - 1);
79 string_len
+= sizeof "POSIX_V7_ILP32_OFFBIG" - 1;
82 #ifndef _POSIX_V7_LP64_OFF64
83 if (__sysconf (_SC_V7_LP64_OFF64
) > 0)
85 #if !defined _POSIX_V7_LP64_OFF64 || _POSIX_V7_LP64_OFF64 > 0
88 restenvs
[string_len
++] = '\n';
89 memcpy (restenvs
+ string_len
, "POSIX_V7_LP64_OFF64",
90 sizeof "POSIX_V7_LP64_OFF64" - 1);
91 string_len
+= sizeof "POSIX_V7_LP64_OFF64" - 1;
94 #ifndef _POSIX_V7_LPBIG_OFFBIG
95 if (__sysconf (_SC_V7_LPBIG_OFFBIG
) > 0)
97 #if !defined _POSIX_V7_LPBIG_OFFBIG || _POSIX_V7_LPBIG_OFFBIG > 0
100 restenvs
[string_len
++] = '\n';
101 memcpy (restenvs
+ string_len
, "POSIX_V7_LPBIG_OFFBIG",
102 sizeof "POSIX_V7_LPBIG_OFFBIG" - 1);
103 string_len
+= sizeof "POSIX_V7_LPBIG_OFFBIG" - 1;
106 restenvs
[string_len
++] = '\0';
110 case _CS_V6_WIDTH_RESTRICTED_ENVS
:
111 /* We have to return a newline-separated list of named of
112 programming environements in which the widths of blksize_t,
113 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
114 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
115 wint_t types are no greater than the width of type long.
117 Currently this means all environment which the system allows. */
119 #ifndef _POSIX_V6_ILP32_OFF32
120 if (__sysconf (_SC_V6_ILP32_OFF32
) > 0)
122 #if !defined _POSIX_V6_ILP32_OFF32 || _POSIX_V6_ILP32_OFF32 > 0
124 memcpy (restenvs
+ string_len
, "POSIX_V6_ILP32_OFF32",
125 sizeof "POSIX_V6_ILP32_OFF32" - 1);
126 string_len
+= sizeof "POSIX_V6_ILP32_OFF32" - 1;
129 #ifndef _POSIX_V6_ILP32_OFFBIG
130 if (__sysconf (_SC_V6_ILP32_OFFBIG
) > 0)
132 #if !defined _POSIX_V6_ILP32_OFFBIG || _POSIX_V6_ILP32_OFFBIG > 0
135 restenvs
[string_len
++] = '\n';
136 memcpy (restenvs
+ string_len
, "POSIX_V6_ILP32_OFFBIG",
137 sizeof "POSIX_V6_ILP32_OFFBIG" - 1);
138 string_len
+= sizeof "POSIX_V6_ILP32_OFFBIG" - 1;
141 #ifndef _POSIX_V6_LP64_OFF64
142 if (__sysconf (_SC_V6_LP64_OFF64
) > 0)
144 #if !defined _POSIX_V6_LP64_OFF64 || _POSIX_V6_LP64_OFF64 > 0
147 restenvs
[string_len
++] = '\n';
148 memcpy (restenvs
+ string_len
, "POSIX_V6_LP64_OFF64",
149 sizeof "POSIX_V6_LP64_OFF64" - 1);
150 string_len
+= sizeof "POSIX_V6_LP64_OFF64" - 1;
153 #ifndef _POSIX_V6_LPBIG_OFFBIG
154 if (__sysconf (_SC_V6_LPBIG_OFFBIG
) > 0)
156 #if !defined _POSIX_V6_LPBIG_OFFBIG || _POSIX_V6_LPBIG_OFFBIG > 0
159 restenvs
[string_len
++] = '\n';
160 memcpy (restenvs
+ string_len
, "POSIX_V6_LPBIG_OFFBIG",
161 sizeof "POSIX_V6_LPBIG_OFFBIG" - 1);
162 string_len
+= sizeof "POSIX_V6_LPBIG_OFFBIG" - 1;
165 restenvs
[string_len
++] = '\0';
169 case _CS_V5_WIDTH_RESTRICTED_ENVS
:
170 /* We have to return a newline-separated list of named of
171 programming environements in which the widths of blksize_t,
172 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
173 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
174 wint_t types are no greater than the width of type long.
176 Currently this means all environment which the system allows. */
178 #ifndef _XBS5_ILP32_OFF32
179 if (__sysconf (_SC_XBS5_ILP32_OFF32
) > 0)
181 #if !defined _XBS5_ILP32_OFF32 || _XBS5_ILP32_OFF32 > 0
183 memcpy (restenvs
+ string_len
, "XBS5_ILP32_OFF32",
184 sizeof "XBS5_ILP32_OFF32" - 1);
185 string_len
+= sizeof "XBS5_ILP32_OFF32" - 1;
188 #ifndef _XBS5_ILP32_OFFBIG
189 if (__sysconf (_SC_XBS5_ILP32_OFFBIG
) > 0)
191 #if !defined _XBS5_ILP32_OFFBIG || _XBS5_ILP32_OFFBIG > 0
194 restenvs
[string_len
++] = '\n';
195 memcpy (restenvs
+ string_len
, "XBS5_ILP32_OFFBIG",
196 sizeof "XBS5_ILP32_OFFBIG" - 1);
197 string_len
+= sizeof "XBS5_ILP32_OFFBIG" - 1;
200 #ifndef _XBS5_LP64_OFF64
201 if (__sysconf (_SC_XBS5_LP64_OFF64
) > 0)
203 #if !defined _XBS5_LP64_OFF64 || _XBS5_LP64_OFF64 > 0
206 restenvs
[string_len
++] = '\n';
207 memcpy (restenvs
+ string_len
, "XBS5_LP64_OFF64",
208 sizeof "XBS5_LP64_OFF64" - 1);
209 string_len
+= sizeof "XBS5_LP64_OFF64" - 1;
212 #ifndef _XBS5_LPBIG_OFFBIG
213 if (__sysconf (_SC_XBS5_LPBIG_OFFBIG
) > 0)
215 #if !defined _XBS5_LPBIG_OFFBIG || _XBS5_LPBIG_OFFBIG > 0
218 restenvs
[string_len
++] = '\n';
219 memcpy (restenvs
+ string_len
, "XBS5_LPBIG_OFFBIG",
220 sizeof "XBS5_LPBIG_OFFBIG" - 1);
221 string_len
+= sizeof "XBS5_LPBIG_OFFBIG" - 1;
224 restenvs
[string_len
++] = '\0';
228 case _CS_XBS5_ILP32_OFF32_CFLAGS
:
229 case _CS_POSIX_V6_ILP32_OFF32_CFLAGS
:
230 case _CS_POSIX_V7_ILP32_OFF32_CFLAGS
:
231 #ifdef __ILP32_OFF32_CFLAGS
232 # if _POSIX_V7_ILP32_OFF32 == -1
233 # error "__ILP32_OFF32_CFLAGS should not be defined"
234 # elif !defined _POSIX_V7_ILP32_OFF32
235 if (__sysconf (_SC_V7_ILP32_OFF32
) < 0)
238 string
= __ILP32_OFF32_CFLAGS
;
239 string_len
= sizeof (__ILP32_OFF32_CFLAGS
);
243 case _CS_XBS5_ILP32_OFFBIG_CFLAGS
:
244 case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS
:
245 case _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS
:
246 #ifdef __ILP32_OFFBIG_CFLAGS
247 # if _POSIX_V7_ILP32_OFFBIG == -1
248 # error "__ILP32_OFFBIG_CFLAGS should not be defined"
249 # elif !defined _POSIX_V7_ILP32_OFFBIG
250 if (__sysconf (_SC_V7_ILP32_OFFBIG
) < 0)
253 string
= __ILP32_OFFBIG_CFLAGS
;
254 string_len
= sizeof (__ILP32_OFFBIG_CFLAGS
);
258 case _CS_XBS5_LP64_OFF64_CFLAGS
:
259 case _CS_POSIX_V6_LP64_OFF64_CFLAGS
:
260 case _CS_POSIX_V7_LP64_OFF64_CFLAGS
:
261 #ifdef __LP64_OFF64_CFLAGS
262 # if _POSIX_V7_LP64_OFF64 == -1
263 # error "__LP64_OFF64_CFLAGS should not be defined"
264 # elif !defined _POSIX_V7_LP64_OFF64
265 if (__sysconf (_SC_V7_LP64_OFF64
) < 0)
268 string
= __LP64_OFF64_CFLAGS
;
269 string_len
= sizeof (__LP64_OFF64_CFLAGS
);
273 case _CS_XBS5_ILP32_OFF32_LDFLAGS
:
274 case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS
:
275 case _CS_POSIX_V7_ILP32_OFF32_LDFLAGS
:
276 #ifdef __ILP32_OFF32_LDFLAGS
277 # if _POSIX_V7_ILP32_OFF32 == -1
278 # error "__ILP32_OFF32_LDFLAGS should not be defined"
279 # elif !defined _POSIX_V7_ILP32_OFF32
280 if (__sysconf (_SC_V7_ILP32_OFF32
) < 0)
283 string
= __ILP32_OFF32_LDFLAGS
;
284 string_len
= sizeof (__ILP32_OFF32_LDFLAGS
);
288 case _CS_XBS5_ILP32_OFFBIG_LDFLAGS
:
289 case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS
:
290 case _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS
:
291 #ifdef __ILP32_OFFBIG_LDFLAGS
292 # if _POSIX_V7_ILP32_OFFBIG == -1
293 # error "__ILP32_OFFBIG_LDFLAGS should not be defined"
294 # elif !defined _POSIX_V7_ILP32_OFFBIG
295 if (__sysconf (_SC_V7_ILP32_OFFBIG
) < 0)
298 string
= __ILP32_OFFBIG_LDFLAGS
;
299 string_len
= sizeof (__ILP32_OFFBIG_LDFLAGS
);
303 case _CS_XBS5_LP64_OFF64_LDFLAGS
:
304 case _CS_POSIX_V6_LP64_OFF64_LDFLAGS
:
305 case _CS_POSIX_V7_LP64_OFF64_LDFLAGS
:
306 #ifdef __LP64_OFF64_LDFLAGS
307 # if _POSIX_V7_LP64_OFF64 == -1
308 # error "__LP64_OFF64_LDFLAGS should not be defined"
309 # elif !defined _POSIX_V7_LP64_OFF64
310 if (__sysconf (_SC_V7_LP64_OFF64
) < 0)
313 string
= __LP64_OFF64_LDFLAGS
;
314 string_len
= sizeof (__LP64_OFF64_LDFLAGS
);
319 case _CS_LFS_LINTFLAGS
:
320 #if _POSIX_V6_ILP32_OFF32 == 1 && _POSIX_V6_ILP32_OFFBIG == 1
321 # define __LFS_CFLAGS "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
322 /* Signal that we want the new ABI. */
323 string
= __LFS_CFLAGS
;
324 string_len
= sizeof (__LFS_CFLAGS
);
328 case _CS_LFS_LDFLAGS
:
330 /* No special libraries or linker flags needed. */
333 case _CS_LFS64_CFLAGS
:
334 case _CS_LFS64_LINTFLAGS
:
335 #define __LFS64_CFLAGS "-D_LARGEFILE64_SOURCE"
336 string
= __LFS64_CFLAGS
;
337 string_len
= sizeof (__LFS64_CFLAGS
);
340 case _CS_LFS64_LDFLAGS
:
342 /* No special libraries or linker flags needed. */
345 case _CS_XBS5_ILP32_OFF32_LIBS
:
346 case _CS_XBS5_ILP32_OFF32_LINTFLAGS
:
347 case _CS_XBS5_ILP32_OFFBIG_LIBS
:
348 case _CS_XBS5_ILP32_OFFBIG_LINTFLAGS
:
349 case _CS_XBS5_LP64_OFF64_LIBS
:
350 case _CS_XBS5_LP64_OFF64_LINTFLAGS
:
351 case _CS_XBS5_LPBIG_OFFBIG_CFLAGS
:
352 case _CS_XBS5_LPBIG_OFFBIG_LDFLAGS
:
353 case _CS_XBS5_LPBIG_OFFBIG_LIBS
:
354 case _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS
:
356 case _CS_POSIX_V6_ILP32_OFF32_LIBS
:
357 case _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS
:
358 case _CS_POSIX_V6_ILP32_OFFBIG_LIBS
:
359 case _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS
:
360 case _CS_POSIX_V6_LP64_OFF64_LIBS
:
361 case _CS_POSIX_V6_LP64_OFF64_LINTFLAGS
:
362 case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS
:
363 case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS
:
364 case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS
:
365 case _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
:
367 case _CS_POSIX_V7_ILP32_OFF32_LIBS
:
368 case _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS
:
369 case _CS_POSIX_V7_ILP32_OFFBIG_LIBS
:
370 case _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS
:
371 case _CS_POSIX_V7_LP64_OFF64_LIBS
:
372 case _CS_POSIX_V7_LP64_OFF64_LINTFLAGS
:
373 case _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS
:
374 case _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS
:
375 case _CS_POSIX_V7_LPBIG_OFFBIG_LIBS
:
376 case _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS
:
377 /* GNU libc does not require special actions to use LFS functions. */
380 case _CS_GNU_LIBC_VERSION
:
381 string
= "glibc " VERSION
;
382 string_len
= sizeof ("glibc " VERSION
);
385 case _CS_GNU_LIBPTHREAD_VERSION
:
386 #ifdef LIBPTHREAD_VERSION
387 string
= LIBPTHREAD_VERSION
;
388 string_len
= sizeof LIBPTHREAD_VERSION
;
391 /* No thread library. */
392 __set_errno (EINVAL
);
398 /* Maybe something else is needed in future. */
399 string
= "POSIXLY_CORRECT=1";
400 string_len
= sizeof ("POSIXLY_CORRECT=1");
404 __set_errno (EINVAL
);
408 if (len
> 0 && buf
!= NULL
)
410 if (string_len
<= len
)
411 memcpy (buf
, string
, string_len
);
414 memcpy (buf
, string
, len
- 1);
420 libc_hidden_def (confstr
)