Fix configure logic for disabling multi-arch.
[glibc.git] / posix / confstr.c
blob3c9566d1cfe998d85295ac91817498c75fffe6e9
1 /* Copyright (C) 1991,1996,1997,2000-2004,2009,2010 Free
2 Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <stddef.h>
20 #include <errno.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <confstr.h>
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. */
29 size_t
30 confstr (name, buf, len)
31 int name;
32 char *buf;
33 size_t len;
35 const char *string = "";
36 size_t string_len = 1;
38 switch (name)
40 case _CS_PATH:
42 static const char cs_path[] = CS_PATH;
43 string = cs_path;
44 string_len = sizeof (cs_path);
46 break;
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"];
59 string_len = 0;
60 #ifndef _POSIX_V7_ILP32_OFF32
61 if (__sysconf (_SC_V7_ILP32_OFF32) > 0)
62 #endif
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;
69 #endif
70 #ifndef _POSIX_V7_ILP32_OFFBIG
71 if (__sysconf (_SC_V7_ILP32_OFFBIG) > 0)
72 #endif
73 #if !defined _POSIX_V7_ILP32_OFFBIG || _POSIX_V7_ILP32_OFFBIG > 0
75 if (string_len)
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;
81 #endif
82 #ifndef _POSIX_V7_LP64_OFF64
83 if (__sysconf (_SC_V7_LP64_OFF64) > 0)
84 #endif
85 #if !defined _POSIX_V7_LP64_OFF64 || _POSIX_V7_LP64_OFF64 > 0
87 if (string_len)
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;
93 #endif
94 #ifndef _POSIX_V7_LPBIG_OFFBIG
95 if (__sysconf (_SC_V7_LPBIG_OFFBIG) > 0)
96 #endif
97 #if !defined _POSIX_V7_LPBIG_OFFBIG || _POSIX_V7_LPBIG_OFFBIG > 0
99 if (string_len)
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;
105 #endif
106 restenvs[string_len++] = '\0';
107 string = restenvs;
109 break;
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"];
122 string_len = 0;
123 #ifndef _POSIX_V6_ILP32_OFF32
124 if (__sysconf (_SC_V6_ILP32_OFF32) > 0)
125 #endif
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;
132 #endif
133 #ifndef _POSIX_V6_ILP32_OFFBIG
134 if (__sysconf (_SC_V6_ILP32_OFFBIG) > 0)
135 #endif
136 #if !defined _POSIX_V6_ILP32_OFFBIG || _POSIX_V6_ILP32_OFFBIG > 0
138 if (string_len)
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;
144 #endif
145 #ifndef _POSIX_V6_LP64_OFF64
146 if (__sysconf (_SC_V6_LP64_OFF64) > 0)
147 #endif
148 #if !defined _POSIX_V6_LP64_OFF64 || _POSIX_V6_LP64_OFF64 > 0
150 if (string_len)
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;
156 #endif
157 #ifndef _POSIX_V6_LPBIG_OFFBIG
158 if (__sysconf (_SC_V6_LPBIG_OFFBIG) > 0)
159 #endif
160 #if !defined _POSIX_V6_LPBIG_OFFBIG || _POSIX_V6_LPBIG_OFFBIG > 0
162 if (string_len)
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;
168 #endif
169 restenvs[string_len++] = '\0';
170 string = restenvs;
172 break;
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"];
185 string_len = 0;
186 #ifndef _XBS5_ILP32_OFF32
187 if (__sysconf (_SC_XBS5_ILP32_OFF32) > 0)
188 #endif
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;
195 #endif
196 #ifndef _XBS5_ILP32_OFFBIG
197 if (__sysconf (_SC_XBS5_ILP32_OFFBIG) > 0)
198 #endif
199 #if !defined _XBS5_ILP32_OFFBIG || _XBS5_ILP32_OFFBIG > 0
201 if (string_len)
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;
207 #endif
208 #ifndef _XBS5_LP64_OFF64
209 if (__sysconf (_SC_XBS5_LP64_OFF64) > 0)
210 #endif
211 #if !defined _XBS5_LP64_OFF64 || _XBS5_LP64_OFF64 > 0
213 if (string_len)
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;
219 #endif
220 #ifndef _XBS5_LPBIG_OFFBIG
221 if (__sysconf (_SC_XBS5_LPBIG_OFFBIG) > 0)
222 #endif
223 #if !defined _XBS5_LPBIG_OFFBIG || _XBS5_LPBIG_OFFBIG > 0
225 if (string_len)
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;
231 #endif
232 restenvs[string_len++] = '\0';
233 string = restenvs;
235 break;
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)
245 break;
246 # endif
247 string = __ILP32_OFF32_CFLAGS;
248 string_len = sizeof (__ILP32_OFF32_CFLAGS);
249 #endif
250 break;
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)
260 break;
261 # endif
262 string = __ILP32_OFFBIG_CFLAGS;
263 string_len = sizeof (__ILP32_OFFBIG_CFLAGS);
264 #endif
265 break;
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)
275 break;
276 # endif
277 string = __LP64_OFF64_CFLAGS;
278 string_len = sizeof (__LP64_OFF64_CFLAGS);
279 #endif
280 break;
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)
290 break;
291 # endif
292 string = __ILP32_OFF32_LDFLAGS;
293 string_len = sizeof (__ILP32_OFF32_LDFLAGS);
294 #endif
295 break;
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)
305 break;
306 # endif
307 string = __ILP32_OFFBIG_LDFLAGS;
308 string_len = sizeof (__ILP32_OFFBIG_LDFLAGS);
309 #endif
310 break;
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)
320 break;
321 # endif
322 string = __LP64_OFF64_LDFLAGS;
323 string_len = sizeof (__LP64_OFF64_LDFLAGS);
324 #endif
325 break;
327 case _CS_LFS_CFLAGS:
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);
334 #endif
335 break;
337 case _CS_LFS_LDFLAGS:
338 case _CS_LFS_LIBS:
339 /* No special libraries or linker flags needed. */
340 break;
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);
347 break;
349 case _CS_LFS64_LDFLAGS:
350 case _CS_LFS64_LIBS:
351 /* No special libraries or linker flags needed. */
352 break;
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. */
387 break;
389 case _CS_GNU_LIBC_VERSION:
390 string = "glibc " VERSION;
391 string_len = sizeof ("glibc " VERSION);
392 break;
394 case _CS_GNU_LIBPTHREAD_VERSION:
395 #ifdef LIBPTHREAD_VERSION
396 string = LIBPTHREAD_VERSION;
397 string_len = sizeof LIBPTHREAD_VERSION;
398 break;
399 #else
400 /* No thread library. */
401 __set_errno (EINVAL);
402 return 0;
403 #endif
405 case _CS_V6_ENV:
406 case _CS_V7_ENV:
407 /* Maybe something else is needed in future. */
408 string = "POSIXLY_CORRECT=1";
409 string_len = sizeof ("POSIXLY_CORRECT=1");
410 break;
412 default:
413 __set_errno (EINVAL);
414 return 0;
417 if (len > 0 && buf != NULL)
419 if (string_len <= len)
420 memcpy (buf, string, string_len);
421 else
423 memcpy (buf, string, len - 1);
424 buf[len - 1] = '\0';
427 return string_len;
429 libc_hidden_def (confstr)