1 /* Copyright (C) 1991-2015 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 #define NEED_SPEC_ARRAY 0
26 #include <posix-conf-vars.h>
28 /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
29 of BUF with the value corresponding to NAME and zero-terminate BUF.
30 Return the number of bytes required to hold NAME's entire value. */
32 confstr (name
, buf
, len
)
37 const char *string
= "";
38 size_t string_len
= 1;
40 /* Note that this buffer must be large enough for the longest strings
42 char restenvs
[4 * sizeof "POSIX_V7_LPBIG_OFFBIG"];
48 static const char cs_path
[] = CS_PATH
;
50 string_len
= sizeof (cs_path
);
54 /* For _CS_V7_WIDTH_RESTRICTED_ENVS, _CS_V6_WIDTH_RESTRICTED_ENVS
55 and _CS_V5_WIDTH_RESTRICTED_ENVS:
57 We have to return a newline-separated list of names of
58 programming environments in which the widths of blksize_t,
59 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
60 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
61 wint_t types are no greater than the width of type long.
63 Currently this means all environments that the system allows. */
65 #define START_ENV_GROUP(VERSION) \
66 case _CS_##VERSION##_WIDTH_RESTRICTED_ENVS: \
69 #define END_ENV_GROUP(VERSION) \
70 restenvs[string_len++] = '\0'; \
74 #define KNOWN_ABSENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX) \
77 #define KNOWN_PRESENT_ENV_STRING(STR) \
79 restenvs[string_len++] = '\n'; \
80 memcpy (restenvs + string_len, STR, \
82 string_len += sizeof STR - 1;
84 #define KNOWN_PRESENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX) \
85 KNOWN_PRESENT_ENV_STRING (#ENV_PREFIX "_" #SUFFIX)
87 #define UNKNOWN_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX) \
88 if (__sysconf (_SC_##SC_PREFIX##_##SUFFIX) > 0) \
90 KNOWN_PRESENT_ENVIRONMENT (SC_PREFIX, ENV_PREFIX, SUFFIX) \
93 #include "posix-envs.def"
95 #undef START_ENV_GROUP
97 #undef KNOWN_ABSENT_ENVIRONMENT
98 #undef KNOWN_PRESENT_ENV_STRING
99 #undef KNOWN_PRESENT_ENVIRONMENT
100 #undef UNKNOWN_ENVIRONMENT
102 case _CS_XBS5_ILP32_OFF32_CFLAGS
:
103 case _CS_POSIX_V6_ILP32_OFF32_CFLAGS
:
104 case _CS_POSIX_V7_ILP32_OFF32_CFLAGS
:
105 #ifdef __ILP32_OFF32_CFLAGS
106 # if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFF32)
107 # error "__ILP32_OFF32_CFLAGS should not be defined"
108 # elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFF32)
109 if (__sysconf (_SC_V7_ILP32_OFF32
) < 0)
112 string
= __ILP32_OFF32_CFLAGS
;
113 string_len
= sizeof (__ILP32_OFF32_CFLAGS
);
117 case _CS_XBS5_ILP32_OFFBIG_CFLAGS
:
118 case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS
:
119 case _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS
:
120 #ifdef __ILP32_OFFBIG_CFLAGS
121 # if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFFBIG)
122 # error "__ILP32_OFFBIG_CFLAGS should not be defined"
123 # elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFFBIG)
124 if (__sysconf (_SC_V7_ILP32_OFFBIG
) < 0)
127 string
= __ILP32_OFFBIG_CFLAGS
;
128 string_len
= sizeof (__ILP32_OFFBIG_CFLAGS
);
132 case _CS_XBS5_LP64_OFF64_CFLAGS
:
133 case _CS_POSIX_V6_LP64_OFF64_CFLAGS
:
134 case _CS_POSIX_V7_LP64_OFF64_CFLAGS
:
135 #ifdef __LP64_OFF64_CFLAGS
136 # if CONF_IS_DEFINED_UNSET (_POSIX_V7_LP64_OFF64)
137 # error "__LP64_OFF64_CFLAGS should not be defined"
138 # elif CONF_IS_UNDEFINED (_POSIX_V7_LP64_OFF64)
139 if (__sysconf (_SC_V7_LP64_OFF64
) < 0)
142 string
= __LP64_OFF64_CFLAGS
;
143 string_len
= sizeof (__LP64_OFF64_CFLAGS
);
147 case _CS_XBS5_ILP32_OFF32_LDFLAGS
:
148 case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS
:
149 case _CS_POSIX_V7_ILP32_OFF32_LDFLAGS
:
150 #ifdef __ILP32_OFF32_LDFLAGS
151 # if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFF32 )
152 # error "__ILP32_OFF32_LDFLAGS should not be defined"
153 # elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFF32)
154 if (__sysconf (_SC_V7_ILP32_OFF32
) < 0)
157 string
= __ILP32_OFF32_LDFLAGS
;
158 string_len
= sizeof (__ILP32_OFF32_LDFLAGS
);
162 case _CS_XBS5_ILP32_OFFBIG_LDFLAGS
:
163 case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS
:
164 case _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS
:
165 #ifdef __ILP32_OFFBIG_LDFLAGS
166 # if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFFBIG)
167 # error "__ILP32_OFFBIG_LDFLAGS should not be defined"
168 # elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFFBIG)
169 if (__sysconf (_SC_V7_ILP32_OFFBIG
) < 0)
172 string
= __ILP32_OFFBIG_LDFLAGS
;
173 string_len
= sizeof (__ILP32_OFFBIG_LDFLAGS
);
177 case _CS_XBS5_LP64_OFF64_LDFLAGS
:
178 case _CS_POSIX_V6_LP64_OFF64_LDFLAGS
:
179 case _CS_POSIX_V7_LP64_OFF64_LDFLAGS
:
180 #ifdef __LP64_OFF64_LDFLAGS
181 # if CONF_IS_DEFINED_UNSET (_POSIX_V7_LP64_OFF64)
182 # error "__LP64_OFF64_LDFLAGS should not be defined"
183 # elif CONF_IS_UNDEFINED (_POSIX_V7_LP64_OFF64)
184 if (__sysconf (_SC_V7_LP64_OFF64
) < 0)
187 string
= __LP64_OFF64_LDFLAGS
;
188 string_len
= sizeof (__LP64_OFF64_LDFLAGS
);
193 case _CS_LFS_LINTFLAGS
:
194 #if (CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFF32) \
195 && CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFFBIG))
196 # define __LFS_CFLAGS "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
197 /* Signal that we want the new ABI. */
198 string
= __LFS_CFLAGS
;
199 string_len
= sizeof (__LFS_CFLAGS
);
203 case _CS_LFS_LDFLAGS
:
205 /* No special libraries or linker flags needed. */
208 case _CS_LFS64_CFLAGS
:
209 case _CS_LFS64_LINTFLAGS
:
210 #define __LFS64_CFLAGS "-D_LARGEFILE64_SOURCE"
211 string
= __LFS64_CFLAGS
;
212 string_len
= sizeof (__LFS64_CFLAGS
);
215 case _CS_LFS64_LDFLAGS
:
217 /* No special libraries or linker flags needed. */
220 case _CS_XBS5_ILP32_OFF32_LIBS
:
221 case _CS_XBS5_ILP32_OFF32_LINTFLAGS
:
222 case _CS_XBS5_ILP32_OFFBIG_LIBS
:
223 case _CS_XBS5_ILP32_OFFBIG_LINTFLAGS
:
224 case _CS_XBS5_LP64_OFF64_LIBS
:
225 case _CS_XBS5_LP64_OFF64_LINTFLAGS
:
226 case _CS_XBS5_LPBIG_OFFBIG_CFLAGS
:
227 case _CS_XBS5_LPBIG_OFFBIG_LDFLAGS
:
228 case _CS_XBS5_LPBIG_OFFBIG_LIBS
:
229 case _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS
:
231 case _CS_POSIX_V6_ILP32_OFF32_LIBS
:
232 case _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS
:
233 case _CS_POSIX_V6_ILP32_OFFBIG_LIBS
:
234 case _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS
:
235 case _CS_POSIX_V6_LP64_OFF64_LIBS
:
236 case _CS_POSIX_V6_LP64_OFF64_LINTFLAGS
:
237 case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS
:
238 case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS
:
239 case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS
:
240 case _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
:
242 case _CS_POSIX_V7_ILP32_OFF32_LIBS
:
243 case _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS
:
244 case _CS_POSIX_V7_ILP32_OFFBIG_LIBS
:
245 case _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS
:
246 case _CS_POSIX_V7_LP64_OFF64_LIBS
:
247 case _CS_POSIX_V7_LP64_OFF64_LINTFLAGS
:
248 case _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS
:
249 case _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS
:
250 case _CS_POSIX_V7_LPBIG_OFFBIG_LIBS
:
251 case _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS
:
252 /* GNU libc does not require special actions to use LFS functions. */
255 case _CS_GNU_LIBC_VERSION
:
256 string
= "glibc " VERSION
;
257 string_len
= sizeof ("glibc " VERSION
);
260 case _CS_GNU_LIBPTHREAD_VERSION
:
261 #ifdef LIBPTHREAD_VERSION
262 string
= LIBPTHREAD_VERSION
;
263 string_len
= sizeof LIBPTHREAD_VERSION
;
266 /* No thread library. */
267 __set_errno (EINVAL
);
273 /* Maybe something else is needed in future. */
274 string
= "POSIXLY_CORRECT=1";
275 string_len
= sizeof ("POSIXLY_CORRECT=1");
279 __set_errno (EINVAL
);
283 if (len
> 0 && buf
!= NULL
)
285 if (string_len
<= len
)
286 memcpy (buf
, string
, string_len
);
289 memcpy (buf
, string
, len
- 1);
295 libc_hidden_def (confstr
)