]>
Commit | Line | Data |
---|---|---|
b168057a | 1 | /* Copyright (C) 1991-2015 Free Software Foundation, Inc. |
c84142e8 UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
c84142e8 UD |
8 | |
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 | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
c84142e8 | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
28f540f4 | 17 | |
28f540f4 RM |
18 | #include <stddef.h> |
19 | #include <errno.h> | |
20 | #include <unistd.h> | |
21 | #include <string.h> | |
22 | #include <confstr.h> | |
2067577c | 23 | #include "../version.h" |
50cbbaa9 SP |
24 | |
25 | #define NEED_SPEC_ARRAY 0 | |
4a6aca7b | 26 | #include <posix-conf-vars.h> |
28f540f4 | 27 | |
04ea3b0f UD |
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. */ | |
28f540f4 | 31 | size_t |
c4029823 UD |
32 | confstr (name, buf, len) |
33 | int name; | |
34 | char *buf; | |
35 | size_t len; | |
28f540f4 | 36 | { |
55ed5821 UD |
37 | const char *string = ""; |
38 | size_t string_len = 1; | |
d6a403f9 RM |
39 | |
40 | /* Note that this buffer must be large enough for the longest strings | |
41 | used below. */ | |
ac4c54f0 | 42 | char restenvs[4 * sizeof "POSIX_V7_LPBIG_OFFBIG"]; |
28f540f4 RM |
43 | |
44 | switch (name) | |
45 | { | |
46 | case _CS_PATH: | |
47 | { | |
c4029823 | 48 | static const char cs_path[] = CS_PATH; |
28f540f4 | 49 | string = cs_path; |
c4029823 | 50 | string_len = sizeof (cs_path); |
28f540f4 RM |
51 | } |
52 | break; | |
53 | ||
531f1ae0 JM |
54 | /* For _CS_V7_WIDTH_RESTRICTED_ENVS, _CS_V6_WIDTH_RESTRICTED_ENVS |
55 | and _CS_V5_WIDTH_RESTRICTED_ENVS: | |
56 | ||
57 | We have to return a newline-separated list of names of | |
58 | programming environments in which the widths of blksize_t, | |
26b62243 UD |
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. | |
62 | ||
531f1ae0 JM |
63 | Currently this means all environments that the system allows. */ |
64 | ||
65 | #define START_ENV_GROUP(VERSION) \ | |
66 | case _CS_##VERSION##_WIDTH_RESTRICTED_ENVS: \ | |
ac4c54f0 | 67 | string_len = 0; |
531f1ae0 JM |
68 | |
69 | #define END_ENV_GROUP(VERSION) \ | |
70 | restenvs[string_len++] = '\0'; \ | |
71 | string = restenvs; \ | |
26b62243 UD |
72 | break; |
73 | ||
531f1ae0 JM |
74 | #define KNOWN_ABSENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX) \ |
75 | /* Empty. */ | |
280f4add | 76 | |
531f1ae0 JM |
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; | |
280f4add | 83 | |
531f1ae0 JM |
84 | #define KNOWN_PRESENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX) \ |
85 | KNOWN_PRESENT_ENV_STRING (#ENV_PREFIX "_" #SUFFIX) | |
26b62243 | 86 | |
531f1ae0 JM |
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) \ | |
ac4c54f0 | 91 | } |
531f1ae0 JM |
92 | |
93 | #include "posix-envs.def" | |
94 | ||
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 | |
26b62243 | 101 | |
28f367c4 UD |
102 | case _CS_XBS5_ILP32_OFF32_CFLAGS: |
103 | case _CS_POSIX_V6_ILP32_OFF32_CFLAGS: | |
26b62243 | 104 | case _CS_POSIX_V7_ILP32_OFF32_CFLAGS: |
28f367c4 | 105 | #ifdef __ILP32_OFF32_CFLAGS |
4a6aca7b | 106 | # if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFF32) |
9e68d85a | 107 | # error "__ILP32_OFF32_CFLAGS should not be defined" |
4a6aca7b | 108 | # elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFF32) |
26b62243 | 109 | if (__sysconf (_SC_V7_ILP32_OFF32) < 0) |
f095bb72 | 110 | break; |
28f367c4 UD |
111 | # endif |
112 | string = __ILP32_OFF32_CFLAGS; | |
113 | string_len = sizeof (__ILP32_OFF32_CFLAGS); | |
114 | #endif | |
115 | break; | |
116 | ||
2c179ef0 AJ |
117 | case _CS_XBS5_ILP32_OFFBIG_CFLAGS: |
118 | case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS: | |
26b62243 | 119 | case _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS: |
28f367c4 | 120 | #ifdef __ILP32_OFFBIG_CFLAGS |
4a6aca7b | 121 | # if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFFBIG) |
9e68d85a | 122 | # error "__ILP32_OFFBIG_CFLAGS should not be defined" |
4a6aca7b | 123 | # elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFFBIG) |
26b62243 | 124 | if (__sysconf (_SC_V7_ILP32_OFFBIG) < 0) |
f095bb72 | 125 | break; |
28f367c4 UD |
126 | # endif |
127 | string = __ILP32_OFFBIG_CFLAGS; | |
128 | string_len = sizeof (__ILP32_OFFBIG_CFLAGS); | |
129 | #endif | |
130 | break; | |
131 | ||
132 | case _CS_XBS5_LP64_OFF64_CFLAGS: | |
133 | case _CS_POSIX_V6_LP64_OFF64_CFLAGS: | |
26b62243 | 134 | case _CS_POSIX_V7_LP64_OFF64_CFLAGS: |
28f367c4 | 135 | #ifdef __LP64_OFF64_CFLAGS |
4a6aca7b | 136 | # if CONF_IS_DEFINED_UNSET (_POSIX_V7_LP64_OFF64) |
9e68d85a | 137 | # error "__LP64_OFF64_CFLAGS should not be defined" |
4a6aca7b | 138 | # elif CONF_IS_UNDEFINED (_POSIX_V7_LP64_OFF64) |
26b62243 | 139 | if (__sysconf (_SC_V7_LP64_OFF64) < 0) |
f095bb72 | 140 | break; |
28f367c4 UD |
141 | # endif |
142 | string = __LP64_OFF64_CFLAGS; | |
143 | string_len = sizeof (__LP64_OFF64_CFLAGS); | |
144 | #endif | |
145 | break; | |
146 | ||
147 | case _CS_XBS5_ILP32_OFF32_LDFLAGS: | |
148 | case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS: | |
26b62243 | 149 | case _CS_POSIX_V7_ILP32_OFF32_LDFLAGS: |
28f367c4 | 150 | #ifdef __ILP32_OFF32_LDFLAGS |
4a6aca7b | 151 | # if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFF32 ) |
9e68d85a | 152 | # error "__ILP32_OFF32_LDFLAGS should not be defined" |
4a6aca7b | 153 | # elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFF32) |
26b62243 | 154 | if (__sysconf (_SC_V7_ILP32_OFF32) < 0) |
f095bb72 | 155 | break; |
28f367c4 UD |
156 | # endif |
157 | string = __ILP32_OFF32_LDFLAGS; | |
158 | string_len = sizeof (__ILP32_OFF32_LDFLAGS); | |
159 | #endif | |
160 | break; | |
161 | ||
162 | case _CS_XBS5_ILP32_OFFBIG_LDFLAGS: | |
163 | case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS: | |
26b62243 | 164 | case _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS: |
28f367c4 | 165 | #ifdef __ILP32_OFFBIG_LDFLAGS |
4a6aca7b | 166 | # if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFFBIG) |
9e68d85a | 167 | # error "__ILP32_OFFBIG_LDFLAGS should not be defined" |
4a6aca7b | 168 | # elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFFBIG) |
26b62243 | 169 | if (__sysconf (_SC_V7_ILP32_OFFBIG) < 0) |
f095bb72 | 170 | break; |
28f367c4 UD |
171 | # endif |
172 | string = __ILP32_OFFBIG_LDFLAGS; | |
173 | string_len = sizeof (__ILP32_OFFBIG_LDFLAGS); | |
174 | #endif | |
175 | break; | |
176 | ||
177 | case _CS_XBS5_LP64_OFF64_LDFLAGS: | |
178 | case _CS_POSIX_V6_LP64_OFF64_LDFLAGS: | |
26b62243 | 179 | case _CS_POSIX_V7_LP64_OFF64_LDFLAGS: |
28f367c4 | 180 | #ifdef __LP64_OFF64_LDFLAGS |
4a6aca7b | 181 | # if CONF_IS_DEFINED_UNSET (_POSIX_V7_LP64_OFF64) |
9e68d85a | 182 | # error "__LP64_OFF64_LDFLAGS should not be defined" |
4a6aca7b | 183 | # elif CONF_IS_UNDEFINED (_POSIX_V7_LP64_OFF64) |
26b62243 | 184 | if (__sysconf (_SC_V7_LP64_OFF64) < 0) |
f095bb72 | 185 | break; |
28f367c4 UD |
186 | # endif |
187 | string = __LP64_OFF64_LDFLAGS; | |
188 | string_len = sizeof (__LP64_OFF64_LDFLAGS); | |
189 | #endif | |
190 | break; | |
191 | ||
2c179ef0 | 192 | case _CS_LFS_CFLAGS: |
55ed5821 | 193 | case _CS_LFS_LINTFLAGS: |
4a6aca7b SP |
194 | #if (CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFF32) \ |
195 | && CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFFBIG)) | |
28f367c4 | 196 | # define __LFS_CFLAGS "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" |
2c179ef0 | 197 | /* Signal that we want the new ABI. */ |
28f367c4 UD |
198 | string = __LFS_CFLAGS; |
199 | string_len = sizeof (__LFS_CFLAGS); | |
2c179ef0 | 200 | #endif |
28f367c4 | 201 | break; |
2c179ef0 | 202 | |
dfd2257a UD |
203 | case _CS_LFS_LDFLAGS: |
204 | case _CS_LFS_LIBS: | |
55ed5821 UD |
205 | /* No special libraries or linker flags needed. */ |
206 | break; | |
207 | ||
dfd2257a UD |
208 | case _CS_LFS64_CFLAGS: |
209 | case _CS_LFS64_LINTFLAGS: | |
28f367c4 UD |
210 | #define __LFS64_CFLAGS "-D_LARGEFILE64_SOURCE" |
211 | string = __LFS64_CFLAGS; | |
212 | string_len = sizeof (__LFS64_CFLAGS); | |
55ed5821 UD |
213 | break; |
214 | ||
dfd2257a UD |
215 | case _CS_LFS64_LDFLAGS: |
216 | case _CS_LFS64_LIBS: | |
55ed5821 UD |
217 | /* No special libraries or linker flags needed. */ |
218 | break; | |
86187531 | 219 | |
86187531 UD |
220 | case _CS_XBS5_ILP32_OFF32_LIBS: |
221 | case _CS_XBS5_ILP32_OFF32_LINTFLAGS: | |
86187531 UD |
222 | case _CS_XBS5_ILP32_OFFBIG_LIBS: |
223 | case _CS_XBS5_ILP32_OFFBIG_LINTFLAGS: | |
86187531 UD |
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: | |
d20f21a2 | 230 | |
d20f21a2 UD |
231 | case _CS_POSIX_V6_ILP32_OFF32_LIBS: |
232 | case _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS: | |
d20f21a2 UD |
233 | case _CS_POSIX_V6_ILP32_OFFBIG_LIBS: |
234 | case _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS: | |
d20f21a2 UD |
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: | |
26b62243 UD |
241 | |
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: | |
af6f3906 | 252 | /* GNU libc does not require special actions to use LFS functions. */ |
dfd2257a UD |
253 | break; |
254 | ||
2067577c UD |
255 | case _CS_GNU_LIBC_VERSION: |
256 | string = "glibc " VERSION; | |
5461545a RM |
257 | string_len = sizeof ("glibc " VERSION); |
258 | break; | |
2067577c UD |
259 | |
260 | case _CS_GNU_LIBPTHREAD_VERSION: | |
261 | #ifdef LIBPTHREAD_VERSION | |
262 | string = LIBPTHREAD_VERSION; | |
5461545a | 263 | string_len = sizeof LIBPTHREAD_VERSION; |
2067577c UD |
264 | break; |
265 | #else | |
266 | /* No thread library. */ | |
267 | __set_errno (EINVAL); | |
268 | return 0; | |
269 | #endif | |
270 | ||
f095bb72 UD |
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; | |
277 | ||
28f540f4 | 278 | default: |
c4029823 | 279 | __set_errno (EINVAL); |
28f540f4 RM |
280 | return 0; |
281 | } | |
282 | ||
04ea3b0f UD |
283 | if (len > 0 && buf != NULL) |
284 | { | |
285 | if (string_len <= len) | |
286 | memcpy (buf, string, string_len); | |
287 | else | |
288 | { | |
289 | memcpy (buf, string, len - 1); | |
290 | buf[len - 1] = '\0'; | |
291 | } | |
292 | } | |
28f540f4 RM |
293 | return string_len; |
294 | } | |
c41f555e | 295 | libc_hidden_def (confstr) |