1 /* Copyright (C) 1991,1996,1997,2000-2004,2009 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 #include "../version.h"
26 /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
27 of BUF with the value corresponding to NAME and zero-terminate BUF.
28 Return the number of bytes required to hold NAME's entire value. */
30 confstr (name
, buf
, len
)
35 const char *string
= "";
36 size_t string_len
= 1;
42 static const char cs_path
[] = CS_PATH
;
44 string_len
= sizeof (cs_path
);
48 case _CS_V7_WIDTH_RESTRICTED_ENVS
:
49 /* We have to return a newline-separated list of named of
50 programming environements in which the widths of blksize_t,
51 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
52 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
53 wint_t types are no greater than the width of type long.
55 Currently this means all environment which the system allows. */
57 char restenvs
[4 * sizeof "POSIX_V7_LPBIG_OFFBIG"];
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';
111 case _CS_V6_WIDTH_RESTRICTED_ENVS
:
112 /* We have to return a newline-separated list of named of
113 programming environements in which the widths of blksize_t,
114 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
115 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
116 wint_t types are no greater than the width of type long.
118 Currently this means all environment which the system allows. */
120 char restenvs
[4 * sizeof "POSIX_V6_LPBIG_OFFBIG"];
123 #ifndef _POSIX_V6_ILP32_OFF32
124 if (__sysconf (_SC_V6_ILP32_OFF32
) > 0)
126 #if !defined _POSIX_V6_ILP32_OFF32 || _POSIX_V6_ILP32_OFF32 > 0
128 memcpy (restenvs
+ string_len
, "POSIX_V6_ILP32_OFF32",
129 sizeof "POSIX_V6_ILP32_OFF32" - 1);
130 string_len
+= sizeof "POSIX_V6_ILP32_OFF32" - 1;
133 #ifndef _POSIX_V6_ILP32_OFFBIG
134 if (__sysconf (_SC_V6_ILP32_OFFBIG
) > 0)
136 #if !defined _POSIX_V6_ILP32_OFFBIG || _POSIX_V6_ILP32_OFFBIG > 0
139 restenvs
[string_len
++] = '\n';
140 memcpy (restenvs
+ string_len
, "POSIX_V6_ILP32_OFFBIG",
141 sizeof "POSIX_V6_ILP32_OFFBIG" - 1);
142 string_len
+= sizeof "POSIX_V6_ILP32_OFFBIG" - 1;
145 #ifndef _POSIX_V6_LP64_OFF64
146 if (__sysconf (_SC_V6_LP64_OFF64
) > 0)
148 #if !defined _POSIX_V6_LP64_OFF64 || _POSIX_V6_LP64_OFF64 > 0
151 restenvs
[string_len
++] = '\n';
152 memcpy (restenvs
+ string_len
, "POSIX_V6_LP64_OFF64",
153 sizeof "POSIX_V6_LP64_OFF64" - 1);
154 string_len
+= sizeof "POSIX_V6_LP64_OFF64" - 1;
157 #ifndef _POSIX_V6_LPBIG_OFFBIG
158 if (__sysconf (_SC_V6_LPBIG_OFFBIG
) > 0)
160 #if !defined _POSIX_V6_LPBIG_OFFBIG || _POSIX_V6_LPBIG_OFFBIG > 0
163 restenvs
[string_len
++] = '\n';
164 memcpy (restenvs
+ string_len
, "POSIX_V6_LPBIG_OFFBIG",
165 sizeof "POSIX_V6_LPBIG_OFFBIG" - 1);
166 string_len
+= sizeof "POSIX_V6_LPBIG_OFFBIG" - 1;
169 restenvs
[string_len
++] = '\0';
174 case _CS_V5_WIDTH_RESTRICTED_ENVS
:
175 /* We have to return a newline-separated list of named of
176 programming environements in which the widths of blksize_t,
177 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
178 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
179 wint_t types are no greater than the width of type long.
181 Currently this means all environment which the system allows. */
183 char restenvs
[4 * sizeof "XBS5_LPBIG_OFFBIG"];
186 #ifndef _XBS5_ILP32_OFF32
187 if (__sysconf (_SC_XBS5_ILP32_OFF32
) > 0)
189 #if !defined _XBS5_ILP32_OFF32 || _XBS5_ILP32_OFF32 > 0
191 memcpy (restenvs
+ string_len
, "XBS5_ILP32_OFF32",
192 sizeof "XBS5_ILP32_OFF32" - 1);
193 string_len
+= sizeof "XBS5_ILP32_OFF32" - 1;
196 #ifndef _XBS5_ILP32_OFFBIG
197 if (__sysconf (_SC_XBS5_ILP32_OFFBIG
) > 0)
199 #if !defined _XBS5_ILP32_OFFBIG || _XBS5_ILP32_OFFBIG > 0
202 restenvs
[string_len
++] = '\n';
203 memcpy (restenvs
+ string_len
, "XBS5_ILP32_OFFBIG",
204 sizeof "XBS5_ILP32_OFFBIG" - 1);
205 string_len
+= sizeof "XBS5_ILP32_OFFBIG" - 1;
208 #ifndef _XBS5_LP64_OFF64
209 if (__sysconf (_SC_XBS5_LP64_OFF64
) > 0)
211 #if !defined _XBS5_LP64_OFF64 || _XBS5_LP64_OFF64 > 0
214 restenvs
[string_len
++] = '\n';
215 memcpy (restenvs
+ string_len
, "XBS5_LP64_OFF64",
216 sizeof "XBS5_LP64_OFF64" - 1);
217 string_len
+= sizeof "XBS5_LP64_OFF64" - 1;
220 #ifndef _XBS5_LPBIG_OFFBIG
221 if (__sysconf (_SC_XBS5_LPBIG_OFFBIG
) > 0)
223 #if !defined _XBS5_LPBIG_OFFBIG || _XBS5_LPBIG_OFFBIG > 0
226 restenvs
[string_len
++] = '\n';
227 memcpy (restenvs
+ string_len
, "XBS5_LPBIG_OFFBIG",
228 sizeof "XBS5_LPBIG_OFFBIG" - 1);
229 string_len
+= sizeof "XBS5_LPBIG_OFFBIG" - 1;
232 restenvs
[string_len
++] = '\0';
237 case _CS_XBS5_ILP32_OFF32_CFLAGS
:
238 case _CS_POSIX_V6_ILP32_OFF32_CFLAGS
:
239 case _CS_POSIX_V7_ILP32_OFF32_CFLAGS
:
240 #ifdef __ILP32_OFF32_CFLAGS
241 # if _POSIX_V7_ILP32_OFF32 == -1
242 # error "__ILP32_OFF32_CFLAGS should not be defined"
243 # elif !defined _POSIX_V7_ILP32_OFF32
244 if (__sysconf (_SC_V7_ILP32_OFF32
) < 0)
247 string
= __ILP32_OFF32_CFLAGS
;
248 string_len
= sizeof (__ILP32_OFF32_CFLAGS
);
252 case _CS_XBS5_ILP32_OFFBIG_CFLAGS
:
253 case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS
:
254 case _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS
:
255 #ifdef __ILP32_OFFBIG_CFLAGS
256 # if _POSIX_V7_ILP32_OFFBIG == -1
257 # error "__ILP32_OFFBIG_CFLAGS should not be defined"
258 # elif !defined _POSIX_V7_ILP32_OFFBIG
259 if (__sysconf (_SC_V7_ILP32_OFFBIG
) < 0)
262 string
= __ILP32_OFFBIG_CFLAGS
;
263 string_len
= sizeof (__ILP32_OFFBIG_CFLAGS
);
267 case _CS_XBS5_LP64_OFF64_CFLAGS
:
268 case _CS_POSIX_V6_LP64_OFF64_CFLAGS
:
269 case _CS_POSIX_V7_LP64_OFF64_CFLAGS
:
270 #ifdef __LP64_OFF64_CFLAGS
271 # if _POSIX_V7_LP64_OFF64 == -1
272 # error "__LP64_OFF64_CFLAGS should not be defined"
273 # elif !defined _POSIX_V7_LP64_OFF64
274 if (__sysconf (_SC_V7_LP64_OFF64
) < 0)
277 string
= __LP64_OFF64_CFLAGS
;
278 string_len
= sizeof (__LP64_OFF64_CFLAGS
);
282 case _CS_XBS5_ILP32_OFF32_LDFLAGS
:
283 case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS
:
284 case _CS_POSIX_V7_ILP32_OFF32_LDFLAGS
:
285 #ifdef __ILP32_OFF32_LDFLAGS
286 # if _POSIX_V7_ILP32_OFF32 == -1
287 # error "__ILP32_OFF32_LDFLAGS should not be defined"
288 # elif !defined _POSIX_V7_ILP32_OFF32
289 if (__sysconf (_SC_V7_ILP32_OFF32
) < 0)
292 string
= __ILP32_OFF32_LDFLAGS
;
293 string_len
= sizeof (__ILP32_OFF32_LDFLAGS
);
297 case _CS_XBS5_ILP32_OFFBIG_LDFLAGS
:
298 case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS
:
299 case _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS
:
300 #ifdef __ILP32_OFFBIG_LDFLAGS
301 # if _POSIX_V7_ILP32_OFFBIG == -1
302 # error "__ILP32_OFFBIG_LDFLAGS should not be defined"
303 # elif !defined _POSIX_V7_ILP32_OFFBIG
304 if (__sysconf (_SC_V7_ILP32_OFFBIG
) < 0)
307 string
= __ILP32_OFFBIG_LDFLAGS
;
308 string_len
= sizeof (__ILP32_OFFBIG_LDFLAGS
);
312 case _CS_XBS5_LP64_OFF64_LDFLAGS
:
313 case _CS_POSIX_V6_LP64_OFF64_LDFLAGS
:
314 case _CS_POSIX_V7_LP64_OFF64_LDFLAGS
:
315 #ifdef __LP64_OFF64_LDFLAGS
316 # if _POSIX_V7_LP64_OFF64 == -1
317 # error "__LP64_OFF64_LDFLAGS should not be defined"
318 # elif !defined _POSIX_V7_LP64_OFF64
319 if (__sysconf (_SC_V7_LP64_OFF64
) < 0)
322 string
= __LP64_OFF64_LDFLAGS
;
323 string_len
= sizeof (__LP64_OFF64_LDFLAGS
);
328 case _CS_LFS_LINTFLAGS
:
329 #if _POSIX_V6_ILP32_OFF32 == 1 && _POSIX_V6_ILP32_OFFBIG == 1
330 # define __LFS_CFLAGS "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
331 /* Signal that we want the new ABI. */
332 string
= __LFS_CFLAGS
;
333 string_len
= sizeof (__LFS_CFLAGS
);
337 case _CS_LFS_LDFLAGS
:
339 /* No special libraries or linker flags needed. */
342 case _CS_LFS64_CFLAGS
:
343 case _CS_LFS64_LINTFLAGS
:
344 #define __LFS64_CFLAGS "-D_LARGEFILE64_SOURCE"
345 string
= __LFS64_CFLAGS
;
346 string_len
= sizeof (__LFS64_CFLAGS
);
349 case _CS_LFS64_LDFLAGS
:
351 /* No special libraries or linker flags needed. */
354 case _CS_XBS5_ILP32_OFF32_LIBS
:
355 case _CS_XBS5_ILP32_OFF32_LINTFLAGS
:
356 case _CS_XBS5_ILP32_OFFBIG_LIBS
:
357 case _CS_XBS5_ILP32_OFFBIG_LINTFLAGS
:
358 case _CS_XBS5_LP64_OFF64_LIBS
:
359 case _CS_XBS5_LP64_OFF64_LINTFLAGS
:
360 case _CS_XBS5_LPBIG_OFFBIG_CFLAGS
:
361 case _CS_XBS5_LPBIG_OFFBIG_LDFLAGS
:
362 case _CS_XBS5_LPBIG_OFFBIG_LIBS
:
363 case _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS
:
365 case _CS_POSIX_V6_ILP32_OFF32_LIBS
:
366 case _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS
:
367 case _CS_POSIX_V6_ILP32_OFFBIG_LIBS
:
368 case _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS
:
369 case _CS_POSIX_V6_LP64_OFF64_LIBS
:
370 case _CS_POSIX_V6_LP64_OFF64_LINTFLAGS
:
371 case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS
:
372 case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS
:
373 case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS
:
374 case _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
:
376 case _CS_POSIX_V7_ILP32_OFF32_LIBS
:
377 case _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS
:
378 case _CS_POSIX_V7_ILP32_OFFBIG_LIBS
:
379 case _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS
:
380 case _CS_POSIX_V7_LP64_OFF64_LIBS
:
381 case _CS_POSIX_V7_LP64_OFF64_LINTFLAGS
:
382 case _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS
:
383 case _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS
:
384 case _CS_POSIX_V7_LPBIG_OFFBIG_LIBS
:
385 case _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS
:
386 /* GNU libc does not require special actions to use LFS functions. */
389 case _CS_GNU_LIBC_VERSION
:
390 string
= "glibc " VERSION
;
391 string_len
= sizeof ("glibc " VERSION
);
394 case _CS_GNU_LIBPTHREAD_VERSION
:
395 #ifdef LIBPTHREAD_VERSION
396 string
= LIBPTHREAD_VERSION
;
397 string_len
= sizeof LIBPTHREAD_VERSION
;
400 /* No thread library. */
401 __set_errno (EINVAL
);
406 __set_errno (EINVAL
);
410 if (len
> 0 && buf
!= NULL
)
412 if (string_len
<= len
)
413 memcpy (buf
, string
, string_len
);
416 memcpy (buf
, string
, len
- 1);
422 libc_hidden_def (confstr
)