Add a new benchmark for isinf/isnan/isnormal/isfinite/fpclassify. The test uses 2...
[glibc.git] / posix / confstr.c
blob7271c5c55fb224a8684764287d1811cdaa3f009f
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/>. */
18 #include <stddef.h>
19 #include <errno.h>
20 #include <unistd.h>
21 #include <string.h>
22 #include <confstr.h>
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. */
31 size_t
32 confstr (name, buf, len)
33 int name;
34 char *buf;
35 size_t len;
37 const char *string = "";
38 size_t string_len = 1;
40 /* Note that this buffer must be large enough for the longest strings
41 used below. */
42 char restenvs[4 * sizeof "POSIX_V7_LPBIG_OFFBIG"];
44 switch (name)
46 case _CS_PATH:
48 static const char cs_path[] = CS_PATH;
49 string = cs_path;
50 string_len = sizeof (cs_path);
52 break;
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: \
67 string_len = 0;
69 #define END_ENV_GROUP(VERSION) \
70 restenvs[string_len++] = '\0'; \
71 string = restenvs; \
72 break;
74 #define KNOWN_ABSENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX) \
75 /* Empty. */
77 #define KNOWN_PRESENT_ENV_STRING(STR) \
78 if (string_len > 0) \
79 restenvs[string_len++] = '\n'; \
80 memcpy (restenvs + string_len, STR, \
81 sizeof STR - 1); \
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) \
89 { \
90 KNOWN_PRESENT_ENVIRONMENT (SC_PREFIX, ENV_PREFIX, SUFFIX) \
93 #include "posix-envs.def"
95 #undef START_ENV_GROUP
96 #undef END_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)
110 break;
111 # endif
112 string = __ILP32_OFF32_CFLAGS;
113 string_len = sizeof (__ILP32_OFF32_CFLAGS);
114 #endif
115 break;
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)
125 break;
126 # endif
127 string = __ILP32_OFFBIG_CFLAGS;
128 string_len = sizeof (__ILP32_OFFBIG_CFLAGS);
129 #endif
130 break;
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)
140 break;
141 # endif
142 string = __LP64_OFF64_CFLAGS;
143 string_len = sizeof (__LP64_OFF64_CFLAGS);
144 #endif
145 break;
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)
155 break;
156 # endif
157 string = __ILP32_OFF32_LDFLAGS;
158 string_len = sizeof (__ILP32_OFF32_LDFLAGS);
159 #endif
160 break;
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)
170 break;
171 # endif
172 string = __ILP32_OFFBIG_LDFLAGS;
173 string_len = sizeof (__ILP32_OFFBIG_LDFLAGS);
174 #endif
175 break;
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)
185 break;
186 # endif
187 string = __LP64_OFF64_LDFLAGS;
188 string_len = sizeof (__LP64_OFF64_LDFLAGS);
189 #endif
190 break;
192 case _CS_LFS_CFLAGS:
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);
200 #endif
201 break;
203 case _CS_LFS_LDFLAGS:
204 case _CS_LFS_LIBS:
205 /* No special libraries or linker flags needed. */
206 break;
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);
213 break;
215 case _CS_LFS64_LDFLAGS:
216 case _CS_LFS64_LIBS:
217 /* No special libraries or linker flags needed. */
218 break;
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. */
253 break;
255 case _CS_GNU_LIBC_VERSION:
256 string = "glibc " VERSION;
257 string_len = sizeof ("glibc " VERSION);
258 break;
260 case _CS_GNU_LIBPTHREAD_VERSION:
261 #ifdef LIBPTHREAD_VERSION
262 string = LIBPTHREAD_VERSION;
263 string_len = sizeof LIBPTHREAD_VERSION;
264 break;
265 #else
266 /* No thread library. */
267 __set_errno (EINVAL);
268 return 0;
269 #endif
271 case _CS_V6_ENV:
272 case _CS_V7_ENV:
273 /* Maybe something else is needed in future. */
274 string = "POSIXLY_CORRECT=1";
275 string_len = sizeof ("POSIXLY_CORRECT=1");
276 break;
278 default:
279 __set_errno (EINVAL);
280 return 0;
283 if (len > 0 && buf != NULL)
285 if (string_len <= len)
286 memcpy (buf, string, string_len);
287 else
289 memcpy (buf, string, len - 1);
290 buf[len - 1] = '\0';
293 return string_len;
295 libc_hidden_def (confstr)