]>
Commit | Line | Data |
---|---|---|
26420023 | 1 | /* Copyright (C) 1991-2025 Free Software Foundation, Inc. |
8a9a5931 | 2 | Copyright The GNU Toolchain Authors. |
ba1ffaa1 | 3 | This file is part of the GNU C Library. |
28f540f4 | 4 | |
ba1ffaa1 | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
28f540f4 | 9 | |
ba1ffaa1 UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
28f540f4 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
28f540f4 RM |
18 | |
19 | /* | |
d1646309 | 20 | * ISO C99 Standard: 7.20 General utilities <stdlib.h> |
28f540f4 RM |
21 | */ |
22 | ||
23 | #ifndef _STDLIB_H | |
5107cf1d | 24 | |
6962682f GG |
25 | #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION |
26 | #include <bits/libc-header-start.h> | |
28f540f4 RM |
27 | |
28 | /* Get size_t, wchar_t and NULL from <stddef.h>. */ | |
ae65d4f3 WD |
29 | #define __need_size_t |
30 | #define __need_wchar_t | |
31 | #define __need_NULL | |
28f540f4 RM |
32 | #include <stddef.h> |
33 | ||
50497a16 UD |
34 | __BEGIN_DECLS |
35 | ||
50497a16 UD |
36 | #define _STDLIB_H 1 |
37 | ||
f095bb72 | 38 | #if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H |
9323b58f UD |
39 | /* XPG requires a few symbols from <sys/wait.h> being defined. */ |
40 | # include <bits/waitflags.h> | |
41 | # include <bits/waitstatus.h> | |
42 | ||
9323b58f | 43 | /* Define the macros <sys/wait.h> also would define this way. */ |
b49ab5f4 FW |
44 | # define WEXITSTATUS(status) __WEXITSTATUS (status) |
45 | # define WTERMSIG(status) __WTERMSIG (status) | |
46 | # define WSTOPSIG(status) __WSTOPSIG (status) | |
47 | # define WIFEXITED(status) __WIFEXITED (status) | |
48 | # define WIFSIGNALED(status) __WIFSIGNALED (status) | |
49 | # define WIFSTOPPED(status) __WIFSTOPPED (status) | |
a044c713 | 50 | # ifdef __WIFCONTINUED |
b49ab5f4 | 51 | # define WIFCONTINUED(status) __WIFCONTINUED (status) |
a044c713 | 52 | # endif |
f095bb72 | 53 | #endif /* X/Open or XPG7 and <sys/wait.h> not included. */ |
9323b58f | 54 | |
cf2046ec GG |
55 | /* _FloatN API tests for enablement. */ |
56 | #include <bits/floatn.h> | |
57 | ||
28f540f4 RM |
58 | /* Returned by `div'. */ |
59 | typedef struct | |
60 | { | |
61 | int quot; /* Quotient. */ | |
62 | int rem; /* Remainder. */ | |
63 | } div_t; | |
64 | ||
65 | /* Returned by `ldiv'. */ | |
e518937a | 66 | #ifndef __ldiv_t_defined |
28f540f4 RM |
67 | typedef struct |
68 | { | |
69 | long int quot; /* Quotient. */ | |
70 | long int rem; /* Remainder. */ | |
71 | } ldiv_t; | |
e518937a UD |
72 | # define __ldiv_t_defined 1 |
73 | #endif | |
28f540f4 | 74 | |
ec751a23 | 75 | #if defined __USE_ISOC99 && !defined __lldiv_t_defined |
59dd8641 | 76 | /* Returned by `lldiv'. */ |
7782d0bf | 77 | __extension__ typedef struct |
59dd8641 RM |
78 | { |
79 | long long int quot; /* Quotient. */ | |
80 | long long int rem; /* Remainder. */ | |
81 | } lldiv_t; | |
e518937a | 82 | # define __lldiv_t_defined 1 |
59dd8641 RM |
83 | #endif |
84 | ||
28f540f4 RM |
85 | |
86 | /* The largest number rand will return (same as INT_MAX). */ | |
87 | #define RAND_MAX 2147483647 | |
88 | ||
89 | ||
90 | /* We define these the same for all machines. | |
91 | Changes from this to the outside world should be done in `_exit'. */ | |
92 | #define EXIT_FAILURE 1 /* Failing exit status. */ | |
93 | #define EXIT_SUCCESS 0 /* Successful exit status. */ | |
94 | ||
95 | ||
0200214b RM |
96 | /* Maximum length of a multibyte character in the current locale. */ |
97 | #define MB_CUR_MAX (__ctype_get_mb_cur_max ()) | |
0476597b | 98 | extern size_t __ctype_get_mb_cur_max (void) __THROW __wur; |
28f540f4 RM |
99 | |
100 | ||
101 | /* Convert a string to a floating-point number. */ | |
a784e502 | 102 | extern double atof (const char *__nptr) |
0476597b | 103 | __THROW __attribute_pure__ __nonnull ((1)) __wur; |
28f540f4 | 104 | /* Convert a string to an integer. */ |
a784e502 | 105 | extern int atoi (const char *__nptr) |
0476597b | 106 | __THROW __attribute_pure__ __nonnull ((1)) __wur; |
28f540f4 | 107 | /* Convert a string to a long integer. */ |
a784e502 | 108 | extern long int atol (const char *__nptr) |
0476597b | 109 | __THROW __attribute_pure__ __nonnull ((1)) __wur; |
28f540f4 | 110 | |
acd7f096 | 111 | #ifdef __USE_ISOC99 |
fb4dfa0c | 112 | /* Convert a string to a long long integer. */ |
a784e502 | 113 | __extension__ extern long long int atoll (const char *__nptr) |
0476597b | 114 | __THROW __attribute_pure__ __nonnull ((1)) __wur; |
7cc27f44 UD |
115 | #endif |
116 | ||
28f540f4 | 117 | /* Convert a string to a floating-point number. */ |
a784e502 | 118 | extern double strtod (const char *__restrict __nptr, |
0476597b | 119 | char **__restrict __endptr) |
c0baea34 | 120 | __THROW __nonnull ((1)); |
28f540f4 | 121 | |
ec751a23 | 122 | #ifdef __USE_ISOC99 |
28f540f4 | 123 | /* Likewise for `float' and `long double' sizes of floating-point numbers. */ |
a784e502 | 124 | extern float strtof (const char *__restrict __nptr, |
c0baea34 | 125 | char **__restrict __endptr) __THROW __nonnull ((1)); |
2f6d1f1b | 126 | |
a784e502 | 127 | extern long double strtold (const char *__restrict __nptr, |
be27d08c | 128 | char **__restrict __endptr) |
c0baea34 | 129 | __THROW __nonnull ((1)); |
28f540f4 RM |
130 | #endif |
131 | ||
97255170 JM |
132 | /* Likewise for '_FloatN' and '_FloatNx'. */ |
133 | ||
134 | #if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
135 | extern _Float16 strtof16 (const char *__restrict __nptr, | |
136 | char **__restrict __endptr) | |
137 | __THROW __nonnull ((1)); | |
138 | #endif | |
139 | ||
140 | #if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
141 | extern _Float32 strtof32 (const char *__restrict __nptr, | |
142 | char **__restrict __endptr) | |
143 | __THROW __nonnull ((1)); | |
144 | #endif | |
145 | ||
146 | #if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
147 | extern _Float64 strtof64 (const char *__restrict __nptr, | |
148 | char **__restrict __endptr) | |
149 | __THROW __nonnull ((1)); | |
150 | #endif | |
151 | ||
45f39d45 | 152 | #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT) |
45f39d45 | 153 | extern _Float128 strtof128 (const char *__restrict __nptr, |
97255170 JM |
154 | char **__restrict __endptr) |
155 | __THROW __nonnull ((1)); | |
156 | #endif | |
157 | ||
158 | #if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
159 | extern _Float32x strtof32x (const char *__restrict __nptr, | |
160 | char **__restrict __endptr) | |
161 | __THROW __nonnull ((1)); | |
162 | #endif | |
163 | ||
164 | #if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
165 | extern _Float64x strtof64x (const char *__restrict __nptr, | |
166 | char **__restrict __endptr) | |
167 | __THROW __nonnull ((1)); | |
168 | #endif | |
169 | ||
170 | #if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
171 | extern _Float128x strtof128x (const char *__restrict __nptr, | |
172 | char **__restrict __endptr) | |
45f39d45 PM |
173 | __THROW __nonnull ((1)); |
174 | #endif | |
175 | ||
28f540f4 | 176 | /* Convert a string to a long integer. */ |
a784e502 | 177 | extern long int strtol (const char *__restrict __nptr, |
be27d08c | 178 | char **__restrict __endptr, int __base) |
c0baea34 | 179 | __THROW __nonnull ((1)); |
28f540f4 | 180 | /* Convert a string to an unsigned long integer. */ |
a784e502 | 181 | extern unsigned long int strtoul (const char *__restrict __nptr, |
c1422e5b | 182 | char **__restrict __endptr, int __base) |
c0baea34 | 183 | __THROW __nonnull ((1)); |
28f540f4 | 184 | |
498afc54 | 185 | #ifdef __USE_MISC |
28f540f4 | 186 | /* Convert a string to a quadword integer. */ |
7782d0bf | 187 | __extension__ |
a784e502 | 188 | extern long long int strtoq (const char *__restrict __nptr, |
be27d08c | 189 | char **__restrict __endptr, int __base) |
c0baea34 | 190 | __THROW __nonnull ((1)); |
28f540f4 | 191 | /* Convert a string to an unsigned quadword integer. */ |
7782d0bf | 192 | __extension__ |
a784e502 | 193 | extern unsigned long long int strtouq (const char *__restrict __nptr, |
c1422e5b | 194 | char **__restrict __endptr, int __base) |
c0baea34 | 195 | __THROW __nonnull ((1)); |
acd7f096 | 196 | #endif /* Use misc. */ |
28f540f4 | 197 | |
acd7f096 | 198 | #ifdef __USE_ISOC99 |
76060ec0 | 199 | /* Convert a string to a quadword integer. */ |
7782d0bf | 200 | __extension__ |
a784e502 | 201 | extern long long int strtoll (const char *__restrict __nptr, |
be27d08c | 202 | char **__restrict __endptr, int __base) |
c0baea34 | 203 | __THROW __nonnull ((1)); |
76060ec0 | 204 | /* Convert a string to an unsigned quadword integer. */ |
7782d0bf | 205 | __extension__ |
a784e502 | 206 | extern unsigned long long int strtoull (const char *__restrict __nptr, |
c1422e5b | 207 | char **__restrict __endptr, int __base) |
c0baea34 | 208 | __THROW __nonnull ((1)); |
6a57d931 | 209 | #endif /* ISO C99 or use MISC. */ |
76060ec0 | 210 | |
64924422 JM |
211 | /* Versions of the above functions that handle '0b' and '0B' prefixes |
212 | in base 0 or 2. */ | |
42cc619d | 213 | #if __GLIBC_USE (C23_STRTOL) |
64924422 JM |
214 | # ifdef __REDIRECT |
215 | extern long int __REDIRECT_NTH (strtol, (const char *__restrict __nptr, | |
216 | char **__restrict __endptr, | |
217 | int __base), __isoc23_strtol) | |
218 | __nonnull ((1)); | |
219 | extern unsigned long int __REDIRECT_NTH (strtoul, | |
220 | (const char *__restrict __nptr, | |
221 | char **__restrict __endptr, | |
222 | int __base), __isoc23_strtoul) | |
223 | __nonnull ((1)); | |
224 | # ifdef __USE_MISC | |
225 | __extension__ | |
226 | extern long long int __REDIRECT_NTH (strtoq, (const char *__restrict __nptr, | |
227 | char **__restrict __endptr, | |
228 | int __base), __isoc23_strtoll) | |
229 | __nonnull ((1)); | |
230 | __extension__ | |
231 | extern unsigned long long int __REDIRECT_NTH (strtouq, | |
232 | (const char *__restrict __nptr, | |
233 | char **__restrict __endptr, | |
234 | int __base), __isoc23_strtoull) | |
235 | __nonnull ((1)); | |
236 | # endif | |
237 | __extension__ | |
238 | extern long long int __REDIRECT_NTH (strtoll, (const char *__restrict __nptr, | |
239 | char **__restrict __endptr, | |
240 | int __base), __isoc23_strtoll) | |
241 | __nonnull ((1)); | |
242 | __extension__ | |
243 | extern unsigned long long int __REDIRECT_NTH (strtoull, | |
244 | (const char *__restrict __nptr, | |
245 | char **__restrict __endptr, | |
246 | int __base), __isoc23_strtoull) | |
247 | __nonnull ((1)); | |
248 | # else | |
249 | extern long int __isoc23_strtol (const char *__restrict __nptr, | |
250 | char **__restrict __endptr, int __base) | |
251 | __THROW __nonnull ((1)); | |
252 | extern unsigned long int __isoc23_strtoul (const char *__restrict __nptr, | |
253 | char **__restrict __endptr, | |
254 | int __base) | |
255 | __THROW __nonnull ((1)); | |
256 | __extension__ | |
257 | extern long long int __isoc23_strtoll (const char *__restrict __nptr, | |
258 | char **__restrict __endptr, int __base) | |
259 | __THROW __nonnull ((1)); | |
260 | __extension__ | |
261 | extern unsigned long long int __isoc23_strtoull (const char *__restrict __nptr, | |
262 | char **__restrict __endptr, | |
263 | int __base) | |
264 | __THROW __nonnull ((1)); | |
265 | # define strtol __isoc23_strtol | |
266 | # define strtoul __isoc23_strtoul | |
267 | # ifdef __USE_MISC | |
268 | # define strtoq __isoc23_strtoll | |
269 | # define strtouq __isoc23_strtoull | |
270 | # endif | |
271 | # define strtoll __isoc23_strtoll | |
272 | # define strtoull __isoc23_strtoull | |
273 | # endif | |
274 | #endif | |
275 | ||
6962682f | 276 | /* Convert a floating-point number to a string. */ |
42cc619d | 277 | #if __GLIBC_USE (IEC_60559_BFP_EXT_C23) |
6962682f GG |
278 | extern int strfromd (char *__dest, size_t __size, const char *__format, |
279 | double __f) | |
280 | __THROW __nonnull ((3)); | |
281 | ||
282 | extern int strfromf (char *__dest, size_t __size, const char *__format, | |
283 | float __f) | |
284 | __THROW __nonnull ((3)); | |
285 | ||
286 | extern int strfroml (char *__dest, size_t __size, const char *__format, | |
287 | long double __f) | |
288 | __THROW __nonnull ((3)); | |
289 | #endif | |
290 | ||
97255170 JM |
291 | #if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT) |
292 | extern int strfromf16 (char *__dest, size_t __size, const char * __format, | |
293 | _Float16 __f) | |
294 | __THROW __nonnull ((3)); | |
295 | #endif | |
296 | ||
297 | #if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
298 | extern int strfromf32 (char *__dest, size_t __size, const char * __format, | |
299 | _Float32 __f) | |
300 | __THROW __nonnull ((3)); | |
301 | #endif | |
302 | ||
303 | #if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
304 | extern int strfromf64 (char *__dest, size_t __size, const char * __format, | |
305 | _Float64 __f) | |
306 | __THROW __nonnull ((3)); | |
307 | #endif | |
308 | ||
cf2046ec GG |
309 | #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT) |
310 | extern int strfromf128 (char *__dest, size_t __size, const char * __format, | |
311 | _Float128 __f) | |
312 | __THROW __nonnull ((3)); | |
313 | #endif | |
314 | ||
97255170 JM |
315 | #if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT) |
316 | extern int strfromf32x (char *__dest, size_t __size, const char * __format, | |
317 | _Float32x __f) | |
318 | __THROW __nonnull ((3)); | |
319 | #endif | |
320 | ||
321 | #if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
322 | extern int strfromf64x (char *__dest, size_t __size, const char * __format, | |
323 | _Float64x __f) | |
324 | __THROW __nonnull ((3)); | |
325 | #endif | |
326 | ||
327 | #if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
328 | extern int strfromf128x (char *__dest, size_t __size, const char * __format, | |
329 | _Float128x __f) | |
330 | __THROW __nonnull ((3)); | |
331 | #endif | |
332 | ||
76060ec0 | 333 | |
0501d603 | 334 | #ifdef __USE_GNU |
f0be25b6 ZW |
335 | /* Parallel versions of the functions above which take the locale to |
336 | use as an additional parameter. These are GNU extensions inspired | |
337 | by the POSIX.1-2008 extended locale API. */ | |
338 | # include <bits/types/locale_t.h> | |
339 | ||
a784e502 | 340 | extern long int strtol_l (const char *__restrict __nptr, |
1ab62b32 | 341 | char **__restrict __endptr, int __base, |
af85385f | 342 | locale_t __loc) __THROW __nonnull ((1, 4)); |
0501d603 | 343 | |
a784e502 | 344 | extern unsigned long int strtoul_l (const char *__restrict __nptr, |
1ab62b32 | 345 | char **__restrict __endptr, |
af85385f | 346 | int __base, locale_t __loc) |
c0baea34 | 347 | __THROW __nonnull ((1, 4)); |
0501d603 | 348 | |
7782d0bf | 349 | __extension__ |
a784e502 | 350 | extern long long int strtoll_l (const char *__restrict __nptr, |
1ab62b32 | 351 | char **__restrict __endptr, int __base, |
af85385f | 352 | locale_t __loc) |
c0baea34 | 353 | __THROW __nonnull ((1, 4)); |
0501d603 | 354 | |
7782d0bf | 355 | __extension__ |
a784e502 | 356 | extern unsigned long long int strtoull_l (const char *__restrict __nptr, |
1ab62b32 | 357 | char **__restrict __endptr, |
af85385f | 358 | int __base, locale_t __loc) |
c0baea34 | 359 | __THROW __nonnull ((1, 4)); |
0501d603 | 360 | |
64924422 JM |
361 | /* Versions of the above functions that handle '0b' and '0B' prefixes |
362 | in base 0 or 2. */ | |
42cc619d | 363 | # if __GLIBC_USE (C23_STRTOL) |
64924422 JM |
364 | # ifdef __REDIRECT |
365 | extern long int __REDIRECT_NTH (strtol_l, (const char *__restrict __nptr, | |
366 | char **__restrict __endptr, | |
367 | int __base, locale_t __loc), | |
368 | __isoc23_strtol_l) | |
369 | __nonnull ((1, 4)); | |
370 | extern unsigned long int __REDIRECT_NTH (strtoul_l, | |
371 | (const char *__restrict __nptr, | |
372 | char **__restrict __endptr, | |
373 | int __base, locale_t __loc), | |
374 | __isoc23_strtoul_l) | |
375 | __nonnull ((1, 4)); | |
376 | __extension__ | |
377 | extern long long int __REDIRECT_NTH (strtoll_l, (const char *__restrict __nptr, | |
378 | char **__restrict __endptr, | |
379 | int __base, | |
380 | locale_t __loc), | |
381 | __isoc23_strtoll_l) | |
382 | __nonnull ((1, 4)); | |
383 | __extension__ | |
384 | extern unsigned long long int __REDIRECT_NTH (strtoull_l, | |
385 | (const char *__restrict __nptr, | |
386 | char **__restrict __endptr, | |
387 | int __base, locale_t __loc), | |
388 | __isoc23_strtoull_l) | |
389 | __nonnull ((1, 4)); | |
390 | # else | |
391 | extern long int __isoc23_strtol_l (const char *__restrict __nptr, | |
392 | char **__restrict __endptr, int __base, | |
393 | locale_t __loc) __THROW __nonnull ((1, 4)); | |
394 | extern unsigned long int __isoc23_strtoul_l (const char *__restrict __nptr, | |
395 | char **__restrict __endptr, | |
396 | int __base, locale_t __loc) | |
397 | __THROW __nonnull ((1, 4)); | |
398 | __extension__ | |
399 | extern long long int __isoc23_strtoll_l (const char *__restrict __nptr, | |
400 | char **__restrict __endptr, | |
401 | int __base, locale_t __loc) | |
402 | __THROW __nonnull ((1, 4)); | |
403 | __extension__ | |
404 | extern unsigned long long int __isoc23_strtoull_l (const char *__restrict __nptr, | |
405 | char **__restrict __endptr, | |
406 | int __base, locale_t __loc) | |
407 | __THROW __nonnull ((1, 4)); | |
408 | # define strtol_l __isoc23_strtol_l | |
409 | # define strtoul_l __isoc23_strtoul_l | |
410 | # define strtoll_l __isoc23_strtoll_l | |
411 | # define strtoull_l __isoc23_strtoull_l | |
412 | # endif | |
413 | # endif | |
414 | ||
a784e502 | 415 | extern double strtod_l (const char *__restrict __nptr, |
af85385f | 416 | char **__restrict __endptr, locale_t __loc) |
c0baea34 | 417 | __THROW __nonnull ((1, 3)); |
0501d603 | 418 | |
a784e502 | 419 | extern float strtof_l (const char *__restrict __nptr, |
af85385f | 420 | char **__restrict __endptr, locale_t __loc) |
c0baea34 | 421 | __THROW __nonnull ((1, 3)); |
0501d603 | 422 | |
a784e502 | 423 | extern long double strtold_l (const char *__restrict __nptr, |
1ab62b32 | 424 | char **__restrict __endptr, |
af85385f | 425 | locale_t __loc) |
c0baea34 | 426 | __THROW __nonnull ((1, 3)); |
45f39d45 | 427 | |
97255170 JM |
428 | # if __HAVE_FLOAT16 |
429 | extern _Float16 strtof16_l (const char *__restrict __nptr, | |
430 | char **__restrict __endptr, | |
431 | locale_t __loc) | |
432 | __THROW __nonnull ((1, 3)); | |
433 | # endif | |
434 | ||
435 | # if __HAVE_FLOAT32 | |
436 | extern _Float32 strtof32_l (const char *__restrict __nptr, | |
437 | char **__restrict __endptr, | |
438 | locale_t __loc) | |
439 | __THROW __nonnull ((1, 3)); | |
440 | # endif | |
441 | ||
442 | # if __HAVE_FLOAT64 | |
443 | extern _Float64 strtof64_l (const char *__restrict __nptr, | |
444 | char **__restrict __endptr, | |
445 | locale_t __loc) | |
446 | __THROW __nonnull ((1, 3)); | |
447 | # endif | |
448 | ||
45f39d45 PM |
449 | # if __HAVE_FLOAT128 |
450 | extern _Float128 strtof128_l (const char *__restrict __nptr, | |
451 | char **__restrict __endptr, | |
af85385f | 452 | locale_t __loc) |
45f39d45 PM |
453 | __THROW __nonnull ((1, 3)); |
454 | # endif | |
97255170 JM |
455 | |
456 | # if __HAVE_FLOAT32X | |
457 | extern _Float32x strtof32x_l (const char *__restrict __nptr, | |
458 | char **__restrict __endptr, | |
459 | locale_t __loc) | |
460 | __THROW __nonnull ((1, 3)); | |
461 | # endif | |
462 | ||
463 | # if __HAVE_FLOAT64X | |
464 | extern _Float64x strtof64x_l (const char *__restrict __nptr, | |
465 | char **__restrict __endptr, | |
466 | locale_t __loc) | |
467 | __THROW __nonnull ((1, 3)); | |
468 | # endif | |
469 | ||
470 | # if __HAVE_FLOAT128X | |
471 | extern _Float128x strtof128x_l (const char *__restrict __nptr, | |
472 | char **__restrict __endptr, | |
473 | locale_t __loc) | |
474 | __THROW __nonnull ((1, 3)); | |
475 | # endif | |
0501d603 UD |
476 | #endif /* GNU */ |
477 | ||
f0bf9cb9 | 478 | |
07c416ed | 479 | #ifdef __USE_EXTERN_INLINES |
b037a293 | 480 | __extern_inline int |
a784e502 | 481 | __NTH (atoi (const char *__nptr)) |
2604afb1 UD |
482 | { |
483 | return (int) strtol (__nptr, (char **) NULL, 10); | |
484 | } | |
b037a293 | 485 | __extern_inline long int |
a784e502 | 486 | __NTH (atol (const char *__nptr)) |
2604afb1 UD |
487 | { |
488 | return strtol (__nptr, (char **) NULL, 10); | |
489 | } | |
490 | ||
acd7f096 | 491 | # ifdef __USE_ISOC99 |
b037a293 | 492 | __extension__ __extern_inline long long int |
a784e502 | 493 | __NTH (atoll (const char *__nptr)) |
2604afb1 UD |
494 | { |
495 | return strtoll (__nptr, (char **) NULL, 10); | |
496 | } | |
497 | # endif | |
0c6cee5d | 498 | #endif /* Optimizing and Inlining. */ |
28f540f4 RM |
499 | |
500 | ||
498afc54 | 501 | #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED |
bbed653c RM |
502 | /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant |
503 | digit first. Returns a pointer to static storage overwritten by the | |
504 | next call. */ | |
0476597b | 505 | extern char *l64a (long int __n) __THROW __wur; |
bbed653c | 506 | |
036cc82f | 507 | /* Read a number from a string S in base 64 as above. */ |
a784e502 | 508 | extern long int a64l (const char *__s) |
0476597b | 509 | __THROW __attribute_pure__ __nonnull ((1)) __wur; |
28f540f4 | 510 | |
acd7f096 | 511 | #endif /* Use misc || extended X/Open. */ |
b20e47cb | 512 | |
ed9a38e2 | 513 | #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED |
dfd2257a | 514 | # include <sys/types.h> /* we need int32_t... */ |
b20e47cb | 515 | |
28f540f4 RM |
516 | /* These are the functions that actually do things. The `random', `srandom', |
517 | `initstate' and `setstate' functions are those from BSD Unices. | |
518 | The `rand' and `srand' functions are required by the ANSI standard. | |
519 | We provide both interfaces to the same random number generator. */ | |
354b98cd | 520 | /* Return a random long integer between 0 and 2^31-1 inclusive. */ |
61f9d0a3 | 521 | extern long int random (void) __THROW; |
9ebb936d | 522 | |
28f540f4 | 523 | /* Seed the random number generator with the given number. */ |
c1422e5b | 524 | extern void srandom (unsigned int __seed) __THROW; |
28f540f4 RM |
525 | |
526 | /* Initialize the random number generator to use state buffer STATEBUF, | |
527 | of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16, | |
528 | 32, 64, 128 and 256, the bigger the better; values less than 8 will | |
529 | cause an error and values greater than 256 will be rounded down. */ | |
9323b58f | 530 | extern char *initstate (unsigned int __seed, char *__statebuf, |
be27d08c | 531 | size_t __statelen) __THROW __nonnull ((2)); |
9ebb936d | 532 | |
28f540f4 RM |
533 | /* Switch the random number generator to state buffer STATEBUF, |
534 | which should have been previously initialized by `initstate'. */ | |
be27d08c | 535 | extern char *setstate (char *__statebuf) __THROW __nonnull ((1)); |
28f540f4 | 536 | |
60478656 | 537 | |
2604afb1 | 538 | # ifdef __USE_MISC |
60478656 RM |
539 | /* Reentrant versions of the `random' family of functions. |
540 | These functions all use the following data structure to contain | |
541 | state, rather than global state variables. */ | |
542 | ||
543 | struct random_data | |
544 | { | |
b20e47cb RM |
545 | int32_t *fptr; /* Front pointer. */ |
546 | int32_t *rptr; /* Rear pointer. */ | |
547 | int32_t *state; /* Array of state values. */ | |
60478656 RM |
548 | int rand_type; /* Type of random number generator. */ |
549 | int rand_deg; /* Degree of random number generator. */ | |
550 | int rand_sep; /* Distance between front and rear. */ | |
b20e47cb | 551 | int32_t *end_ptr; /* Pointer behind state table. */ |
60478656 RM |
552 | }; |
553 | ||
c1422e5b | 554 | extern int random_r (struct random_data *__restrict __buf, |
be27d08c | 555 | int32_t *__restrict __result) __THROW __nonnull ((1, 2)); |
8a523922 | 556 | |
be27d08c UD |
557 | extern int srandom_r (unsigned int __seed, struct random_data *__buf) |
558 | __THROW __nonnull ((2)); | |
8a523922 | 559 | |
9323b58f | 560 | extern int initstate_r (unsigned int __seed, char *__restrict __statebuf, |
c1422e5b | 561 | size_t __statelen, |
be27d08c UD |
562 | struct random_data *__restrict __buf) |
563 | __THROW __nonnull ((2, 4)); | |
8a523922 | 564 | |
9323b58f | 565 | extern int setstate_r (char *__restrict __statebuf, |
be27d08c UD |
566 | struct random_data *__restrict __buf) |
567 | __THROW __nonnull ((1, 2)); | |
2604afb1 | 568 | # endif /* Use misc. */ |
acd7f096 | 569 | #endif /* Use extended X/Open || misc. */ |
60478656 RM |
570 | |
571 | ||
2c6fe0bd | 572 | /* Return a random integer between 0 and RAND_MAX inclusive. */ |
c1422e5b | 573 | extern int rand (void) __THROW; |
2c6fe0bd | 574 | /* Seed the random number generator with the given number. */ |
c1422e5b | 575 | extern void srand (unsigned int __seed) __THROW; |
2c6fe0bd | 576 | |
b098852a | 577 | #ifdef __USE_POSIX199506 |
47707456 | 578 | /* Reentrant interface according to POSIX.1. */ |
c1422e5b | 579 | extern int rand_r (unsigned int *__seed) __THROW; |
47707456 UD |
580 | #endif |
581 | ||
2c6fe0bd | 582 | |
498afc54 | 583 | #if defined __USE_MISC || defined __USE_XOPEN |
60478656 RM |
584 | /* System V style 48-bit random number generator functions. */ |
585 | ||
2c6fe0bd | 586 | /* Return non-negative, double-precision floating-point value in [0.0,1.0). */ |
c1422e5b | 587 | extern double drand48 (void) __THROW; |
be27d08c | 588 | extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1)); |
2c6fe0bd UD |
589 | |
590 | /* Return non-negative, long integer in [0,2^31). */ | |
c1422e5b | 591 | extern long int lrand48 (void) __THROW; |
be27d08c UD |
592 | extern long int nrand48 (unsigned short int __xsubi[3]) |
593 | __THROW __nonnull ((1)); | |
2c6fe0bd UD |
594 | |
595 | /* Return signed, long integers in [-2^31,2^31). */ | |
c1422e5b | 596 | extern long int mrand48 (void) __THROW; |
be27d08c UD |
597 | extern long int jrand48 (unsigned short int __xsubi[3]) |
598 | __THROW __nonnull ((1)); | |
2c6fe0bd UD |
599 | |
600 | /* Seed random number generator. */ | |
c1422e5b | 601 | extern void srand48 (long int __seedval) __THROW; |
be27d08c UD |
602 | extern unsigned short int *seed48 (unsigned short int __seed16v[3]) |
603 | __THROW __nonnull ((1)); | |
604 | extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1)); | |
2c6fe0bd | 605 | |
d17c01f9 UD |
606 | # ifdef __USE_MISC |
607 | /* Data structure for communication with thread safe versions. This | |
608 | type is to be regarded as opaque. It's only exported because users | |
609 | have to allocate objects of this type. */ | |
60478656 RM |
610 | struct drand48_data |
611 | { | |
d17c01f9 UD |
612 | unsigned short int __x[3]; /* Current state. */ |
613 | unsigned short int __old_x[3]; /* Old state. */ | |
614 | unsigned short int __c; /* Additive const. in congruential formula. */ | |
615 | unsigned short int __init; /* Flag for initializing. */ | |
828beb13 JM |
616 | __extension__ unsigned long long int __a; /* Factor in congruential |
617 | formula. */ | |
60478656 RM |
618 | }; |
619 | ||
620 | /* Return non-negative, double-precision floating-point value in [0.0,1.0). */ | |
c1422e5b | 621 | extern int drand48_r (struct drand48_data *__restrict __buffer, |
be27d08c | 622 | double *__restrict __result) __THROW __nonnull ((1, 2)); |
c1422e5b UD |
623 | extern int erand48_r (unsigned short int __xsubi[3], |
624 | struct drand48_data *__restrict __buffer, | |
be27d08c | 625 | double *__restrict __result) __THROW __nonnull ((1, 2)); |
2c6fe0bd | 626 | |
60478656 | 627 | /* Return non-negative, long integer in [0,2^31). */ |
c1422e5b | 628 | extern int lrand48_r (struct drand48_data *__restrict __buffer, |
be27d08c UD |
629 | long int *__restrict __result) |
630 | __THROW __nonnull ((1, 2)); | |
c1422e5b UD |
631 | extern int nrand48_r (unsigned short int __xsubi[3], |
632 | struct drand48_data *__restrict __buffer, | |
be27d08c UD |
633 | long int *__restrict __result) |
634 | __THROW __nonnull ((1, 2)); | |
2c6fe0bd | 635 | |
60478656 | 636 | /* Return signed, long integers in [-2^31,2^31). */ |
c1422e5b | 637 | extern int mrand48_r (struct drand48_data *__restrict __buffer, |
be27d08c UD |
638 | long int *__restrict __result) |
639 | __THROW __nonnull ((1, 2)); | |
c1422e5b UD |
640 | extern int jrand48_r (unsigned short int __xsubi[3], |
641 | struct drand48_data *__restrict __buffer, | |
be27d08c UD |
642 | long int *__restrict __result) |
643 | __THROW __nonnull ((1, 2)); | |
2c6fe0bd | 644 | |
60478656 | 645 | /* Seed random number generator. */ |
c1422e5b | 646 | extern int srand48_r (long int __seedval, struct drand48_data *__buffer) |
be27d08c | 647 | __THROW __nonnull ((2)); |
47f13fd4 | 648 | |
c1422e5b | 649 | extern int seed48_r (unsigned short int __seed16v[3], |
be27d08c | 650 | struct drand48_data *__buffer) __THROW __nonnull ((1, 2)); |
47f13fd4 | 651 | |
c1422e5b | 652 | extern int lcong48_r (unsigned short int __param[7], |
be27d08c UD |
653 | struct drand48_data *__buffer) |
654 | __THROW __nonnull ((1, 2)); | |
6f4e0fcf AZN |
655 | |
656 | /* Return a random integer between zero and 2**32-1 (inclusive). */ | |
657 | extern __uint32_t arc4random (void) | |
658 | __THROW __wur; | |
659 | ||
660 | /* Fill the buffer with random data. */ | |
661 | extern void arc4random_buf (void *__buf, size_t __size) | |
662 | __THROW __nonnull ((1)); | |
663 | ||
664 | /* Return a random number between zero (inclusive) and the specified | |
665 | limit (exclusive). */ | |
666 | extern __uint32_t arc4random_uniform (__uint32_t __upper_bound) | |
667 | __THROW __wur; | |
dfd2257a | 668 | # endif /* Use misc. */ |
acd7f096 | 669 | #endif /* Use misc or X/Open. */ |
28f540f4 | 670 | |
28f540f4 | 671 | /* Allocate SIZE bytes of memory. */ |
9bf8e29c AZ |
672 | extern void *malloc (size_t __size) __THROW __attribute_malloc__ |
673 | __attribute_alloc_size__ ((1)) __wur; | |
7ef90c15 | 674 | /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ |
e9e9b245 | 675 | extern void *calloc (size_t __nmemb, size_t __size) |
9bf8e29c | 676 | __THROW __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __wur; |
7ef90c15 | 677 | |
28f540f4 | 678 | /* Re-allocate the previously allocated block |
c1422e5b | 679 | in PTR, making the new block SIZE bytes long. */ |
1c3e748e UD |
680 | /* __attribute_malloc__ is not used, because if realloc returns |
681 | the same pointer that was passed to it, aliasing needs to be allowed | |
682 | between objects pointed by the old and new pointers. */ | |
0476597b | 683 | extern void *realloc (void *__ptr, size_t __size) |
9bf8e29c | 684 | __THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2)); |
2e0bbbfb | 685 | |
c1760eaf MS |
686 | /* Free a block allocated by `malloc', `realloc' or `calloc'. */ |
687 | extern void free (void *__ptr) __THROW; | |
688 | ||
2bda273a | 689 | #ifdef __USE_MISC |
2e0bbbfb DW |
690 | /* Re-allocate the previously allocated block in PTR, making the new |
691 | block large enough for NMEMB elements of SIZE bytes each. */ | |
692 | /* __attribute_malloc__ is not used, because if reallocarray returns | |
693 | the same pointer that was passed to it, aliasing needs to be allowed | |
694 | between objects pointed by the old and new pointers. */ | |
695 | extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size) | |
9bf8e29c | 696 | __THROW __attribute_warn_unused_result__ |
c1760eaf MS |
697 | __attribute_alloc_size__ ((2, 3)) |
698 | __attr_dealloc_free; | |
2e0bbbfb | 699 | |
c1760eaf MS |
700 | /* Add reallocarray as its own deallocator. */ |
701 | extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size) | |
702 | __THROW __attr_dealloc (reallocarray, 1); | |
703 | #endif | |
28f540f4 | 704 | |
acd7f096 | 705 | #ifdef __USE_MISC |
2604afb1 | 706 | # include <alloca.h> |
acd7f096 | 707 | #endif /* Use misc. */ |
28f540f4 | 708 | |
c589e093 | 709 | #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \ |
498afc54 | 710 | || defined __USE_MISC |
28f540f4 | 711 | /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */ |
9bf8e29c AZ |
712 | extern void *valloc (size_t __size) __THROW __attribute_malloc__ |
713 | __attribute_alloc_size__ ((1)) __wur; | |
28f540f4 RM |
714 | #endif |
715 | ||
0758ea0c | 716 | #ifdef __USE_XOPEN2K |
c8c73ac3 | 717 | /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */ |
61f9d0a3 | 718 | extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size) |
5bcbe69f | 719 | __THROW __nonnull ((1)) __wur; |
0758ea0c | 720 | #endif |
28f540f4 | 721 | |
380d7e87 UD |
722 | #ifdef __USE_ISOC11 |
723 | /* ISO C variant of aligned allocation. */ | |
8b43a4cc | 724 | extern void *aligned_alloc (size_t __alignment, size_t __size) |
8a9a5931 JW |
725 | __THROW __attribute_malloc__ __attribute_alloc_align__ ((1)) |
726 | __attribute_alloc_size__ ((2)) __wur; | |
380d7e87 UD |
727 | #endif |
728 | ||
28f540f4 | 729 | /* Abort execution and generate a core-dump. */ |
e3b0b348 | 730 | extern void abort (void) __THROW __attribute__ ((__noreturn__)) __COLD; |
28f540f4 RM |
731 | |
732 | ||
733 | /* Register a function to be called when `exit' is called. */ | |
be27d08c | 734 | extern int atexit (void (*__func) (void)) __THROW __nonnull ((1)); |
610e67ed | 735 | |
4e9e7a35 | 736 | #if defined __USE_ISOC11 || defined __USE_ISOCXX11 |
610e67ed UD |
737 | /* Register a function to be called when `quick_exit' is called. */ |
738 | # ifdef __cplusplus | |
739 | extern "C++" int at_quick_exit (void (*__func) (void)) | |
740 | __THROW __asm ("at_quick_exit") __nonnull ((1)); | |
741 | # else | |
742 | extern int at_quick_exit (void (*__func) (void)) __THROW __nonnull ((1)); | |
743 | # endif | |
744 | #endif | |
28f540f4 RM |
745 | |
746 | #ifdef __USE_MISC | |
747 | /* Register a function to be called with the status | |
748 | given to `exit' and the given argument. */ | |
c1422e5b | 749 | extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg) |
be27d08c | 750 | __THROW __nonnull ((1)); |
28f540f4 RM |
751 | #endif |
752 | ||
753 | /* Call all functions registered with `atexit' and `on_exit', | |
610e67ed | 754 | in the reverse of the order in which they were registered, |
28f540f4 | 755 | perform stdio cleanup, and terminate program execution with STATUS. */ |
c1422e5b | 756 | extern void exit (int __status) __THROW __attribute__ ((__noreturn__)); |
610e67ed | 757 | |
4e9e7a35 | 758 | #if defined __USE_ISOC11 || defined __USE_ISOCXX11 |
610e67ed UD |
759 | /* Call all functions registered with `at_quick_exit' in the reverse |
760 | of the order in which they were registered and terminate program | |
761 | execution with STATUS. */ | |
762 | extern void quick_exit (int __status) __THROW __attribute__ ((__noreturn__)); | |
763 | #endif | |
28f540f4 | 764 | |
ec751a23 | 765 | #ifdef __USE_ISOC99 |
e518937a UD |
766 | /* Terminate the program with STATUS without calling any of the |
767 | functions registered with `atexit' or `on_exit'. */ | |
c1422e5b | 768 | extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__)); |
e518937a UD |
769 | #endif |
770 | ||
28f540f4 RM |
771 | |
772 | /* Return the value of envariable NAME, or NULL if it doesn't exist. */ | |
a784e502 | 773 | extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur; |
28f540f4 | 774 | |
84b3fd84 | 775 | #ifdef __USE_GNU |
d68171ed UD |
776 | /* This function is similar to the above but returns NULL if the |
777 | programs is running with SUID or SGID enabled. */ | |
84b3fd84 | 778 | extern char *secure_getenv (const char *__name) |
0476597b | 779 | __THROW __nonnull ((1)) __wur; |
84b3fd84 | 780 | #endif |
d68171ed | 781 | |
498afc54 | 782 | #if defined __USE_MISC || defined __USE_XOPEN |
28f540f4 RM |
783 | /* The SVID says this is in <stdio.h>, but this seems a better place. */ |
784 | /* Put STRING, which is of the form "NAME=VALUE", in the environment. | |
785 | If there is no `=', remove NAME from the environment. */ | |
be27d08c | 786 | extern int putenv (char *__string) __THROW __nonnull ((1)); |
28f540f4 RM |
787 | #endif |
788 | ||
acd7f096 | 789 | #ifdef __USE_XOPEN2K |
28f540f4 RM |
790 | /* Set NAME to VALUE in the environment. |
791 | If REPLACE is nonzero, overwrite an existing value. */ | |
a784e502 | 792 | extern int setenv (const char *__name, const char *__value, int __replace) |
90692538 | 793 | __THROW __nonnull ((2)); |
196980f5 RM |
794 | |
795 | /* Remove the variable NAME from the environment. */ | |
a784e502 | 796 | extern int unsetenv (const char *__name) __THROW __nonnull ((1)); |
28f540f4 RM |
797 | #endif |
798 | ||
f0e44959 UD |
799 | #ifdef __USE_MISC |
800 | /* The `clearenv' was planned to be added to POSIX.1 but probably | |
801 | never made it. Nevertheless the POSIX.9 standard (POSIX bindings | |
802 | for Fortran 77) requires this function. */ | |
c1422e5b | 803 | extern int clearenv (void) __THROW; |
f0e44959 UD |
804 | #endif |
805 | ||
2c6fe0bd | 806 | |
52e96a80 | 807 | #if defined __USE_MISC \ |
9bde902c | 808 | || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) |
2c6fe0bd UD |
809 | /* Generate a unique temporary file name from TEMPLATE. |
810 | The last six characters of TEMPLATE must be "XXXXXX"; | |
811 | they are replaced with a string that makes the file name unique. | |
349fa79f AJ |
812 | Always returns TEMPLATE, it's either a temporary file name or a null |
813 | string if it cannot get a unique file name. */ | |
814 | extern char *mktemp (char *__template) __THROW __nonnull ((1)); | |
f095bb72 | 815 | #endif |
2c6fe0bd | 816 | |
acd7f096 | 817 | #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 |
2c6fe0bd UD |
818 | /* Generate a unique temporary file name from TEMPLATE. |
819 | The last six characters of TEMPLATE must be "XXXXXX"; | |
820 | they are replaced with a string that makes the filename unique. | |
821 | Returns a file descriptor open on the file for reading and writing, | |
2c008571 UD |
822 | or -1 if it cannot create a uniquely-named file. |
823 | ||
7f3146e7 | 824 | This function is a possible cancellation point and therefore not |
2c008571 | 825 | marked with __THROW. */ |
85adf316 | 826 | # ifndef __USE_FILE_OFFSET64 |
0476597b | 827 | extern int mkstemp (char *__template) __nonnull ((1)) __wur; |
85adf316 UD |
828 | # else |
829 | # ifdef __REDIRECT | |
0476597b UD |
830 | extern int __REDIRECT (mkstemp, (char *__template), mkstemp64) |
831 | __nonnull ((1)) __wur; | |
85adf316 UD |
832 | # else |
833 | # define mkstemp mkstemp64 | |
834 | # endif | |
835 | # endif | |
836 | # ifdef __USE_LARGEFILE64 | |
0476597b | 837 | extern int mkstemp64 (char *__template) __nonnull ((1)) __wur; |
85adf316 | 838 | # endif |
2c6fe0bd UD |
839 | #endif |
840 | ||
7f3146e7 UD |
841 | #ifdef __USE_MISC |
842 | /* Similar to mkstemp, but the template can have a suffix after the | |
843 | XXXXXX. The length of the suffix is specified in the second | |
844 | parameter. | |
845 | ||
846 | This function is a possible cancellation point and therefore not | |
847 | marked with __THROW. */ | |
848 | # ifndef __USE_FILE_OFFSET64 | |
849 | extern int mkstemps (char *__template, int __suffixlen) __nonnull ((1)) __wur; | |
850 | # else | |
851 | # ifdef __REDIRECT | |
852 | extern int __REDIRECT (mkstemps, (char *__template, int __suffixlen), | |
853 | mkstemps64) __nonnull ((1)) __wur; | |
854 | # else | |
855 | # define mkstemps mkstemps64 | |
856 | # endif | |
857 | # endif | |
858 | # ifdef __USE_LARGEFILE64 | |
859 | extern int mkstemps64 (char *__template, int __suffixlen) | |
860 | __nonnull ((1)) __wur; | |
861 | # endif | |
862 | #endif | |
863 | ||
acd7f096 | 864 | #ifdef __USE_XOPEN2K8 |
2e65ca2b UD |
865 | /* Create a unique temporary directory from TEMPLATE. |
866 | The last six characters of TEMPLATE must be "XXXXXX"; | |
867 | they are replaced with a string that makes the directory name unique. | |
868 | Returns TEMPLATE, or a null pointer if it cannot get a unique name. | |
869 | The directory is created mode 700. */ | |
0476597b | 870 | extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur; |
2e65ca2b UD |
871 | #endif |
872 | ||
d7e23b02 UD |
873 | #ifdef __USE_GNU |
874 | /* Generate a unique temporary file name from TEMPLATE similar to | |
875 | mkstemp. But allow the caller to pass additional flags which are | |
876 | used in the open call to create the file.. | |
877 | ||
4c1423ed | 878 | This function is a possible cancellation point and therefore not |
d7e23b02 UD |
879 | marked with __THROW. */ |
880 | # ifndef __USE_FILE_OFFSET64 | |
881 | extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur; | |
882 | # else | |
883 | # ifdef __REDIRECT | |
884 | extern int __REDIRECT (mkostemp, (char *__template, int __flags), mkostemp64) | |
885 | __nonnull ((1)) __wur; | |
886 | # else | |
887 | # define mkostemp mkostemp64 | |
888 | # endif | |
889 | # endif | |
890 | # ifdef __USE_LARGEFILE64 | |
891 | extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur; | |
892 | # endif | |
3a83202d UD |
893 | |
894 | /* Similar to mkostemp, but the template can have a suffix after the | |
895 | XXXXXX. The length of the suffix is specified in the second | |
896 | parameter. | |
897 | ||
898 | This function is a possible cancellation point and therefore not | |
899 | marked with __THROW. */ | |
900 | # ifndef __USE_FILE_OFFSET64 | |
901 | extern int mkostemps (char *__template, int __suffixlen, int __flags) | |
902 | __nonnull ((1)) __wur; | |
903 | # else | |
904 | # ifdef __REDIRECT | |
905 | extern int __REDIRECT (mkostemps, (char *__template, int __suffixlen, | |
906 | int __flags), mkostemps64) | |
907 | __nonnull ((1)) __wur; | |
908 | # else | |
909 | # define mkostemps mkostemps64 | |
910 | # endif | |
911 | # endif | |
912 | # ifdef __USE_LARGEFILE64 | |
913 | extern int mkostemps64 (char *__template, int __suffixlen, int __flags) | |
914 | __nonnull ((1)) __wur; | |
915 | # endif | |
d7e23b02 UD |
916 | #endif |
917 | ||
2c6fe0bd | 918 | |
2c008571 UD |
919 | /* Execute the given line as a shell command. |
920 | ||
921 | This function is a cancellation point and therefore not marked with | |
922 | __THROW. */ | |
a784e502 | 923 | extern int system (const char *__command) __wur; |
28f540f4 RM |
924 | |
925 | ||
fa0bc87c RM |
926 | #ifdef __USE_GNU |
927 | /* Return a malloc'd string containing the canonical absolute name of the | |
11bf311e | 928 | existing named file. */ |
a784e502 | 929 | extern char *canonicalize_file_name (const char *__name) |
c1760eaf MS |
930 | __THROW __nonnull ((1)) __attribute_malloc__ |
931 | __attr_dealloc_free __wur; | |
fa0bc87c RM |
932 | #endif |
933 | ||
498afc54 | 934 | #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED |
b7674b11 UD |
935 | /* Return the canonical absolute name of file NAME. If RESOLVED is |
936 | null, the result is malloc'd; otherwise, if the canonical name is | |
937 | PATH_MAX chars or more, returns null with `errno' set to | |
938 | ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, | |
939 | returns the name in RESOLVED. */ | |
a784e502 | 940 | extern char *realpath (const char *__restrict __name, |
0476597b | 941 | char *__restrict __resolved) __THROW __wur; |
fa0bc87c RM |
942 | #endif |
943 | ||
944 | ||
28f540f4 | 945 | /* Shorthand for type of comparison functions. */ |
60478656 | 946 | #ifndef __COMPAR_FN_T |
2604afb1 | 947 | # define __COMPAR_FN_T |
a784e502 | 948 | typedef int (*__compar_fn_t) (const void *, const void *); |
28f540f4 | 949 | |
2604afb1 | 950 | # ifdef __USE_GNU |
28f540f4 | 951 | typedef __compar_fn_t comparison_fn_t; |
2604afb1 | 952 | # endif |
28f540f4 | 953 | #endif |
e458144c | 954 | #ifdef __USE_GNU |
a784e502 | 955 | typedef int (*__compar_d_fn_t) (const void *, const void *, void *); |
e458144c | 956 | #endif |
28f540f4 RM |
957 | |
958 | /* Do a binary search for KEY in BASE, which consists of NMEMB elements | |
959 | of SIZE bytes each, using COMPAR to perform the comparisons. */ | |
a784e502 | 960 | extern void *bsearch (const void *__key, const void *__base, |
be27d08c | 961 | size_t __nmemb, size_t __size, __compar_fn_t __compar) |
0476597b | 962 | __nonnull ((1, 2, 5)) __wur; |
28f540f4 | 963 | |
41eda41d OB |
964 | #ifdef __USE_EXTERN_INLINES |
965 | # include <bits/stdlib-bsearch.h> | |
966 | #endif | |
967 | ||
28f540f4 RM |
968 | /* Sort NMEMB elements of BASE, of SIZE bytes each, |
969 | using COMPAR to perform the comparisons. */ | |
c1422e5b | 970 | extern void qsort (void *__base, size_t __nmemb, size_t __size, |
be27d08c | 971 | __compar_fn_t __compar) __nonnull ((1, 4)); |
e458144c UD |
972 | #ifdef __USE_GNU |
973 | extern void qsort_r (void *__base, size_t __nmemb, size_t __size, | |
974 | __compar_d_fn_t __compar, void *__arg) | |
975 | __nonnull ((1, 4)); | |
976 | #endif | |
28f540f4 RM |
977 | |
978 | ||
28f540f4 | 979 | /* Return the absolute value of X. */ |
0476597b UD |
980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur; |
981 | extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur; | |
7a5affeb | 982 | |
ec751a23 | 983 | #ifdef __USE_ISOC99 |
c1422e5b | 984 | __extension__ extern long long int llabs (long long int __x) |
0476597b | 985 | __THROW __attribute__ ((__const__)) __wur; |
59dd8641 | 986 | #endif |
28f540f4 | 987 | |
5b132ec2 LM |
988 | #if __GLIBC_USE (ISOC2Y) |
989 | extern unsigned int uabs (int __x) __THROW __attribute__ ((__const__)) __wur; | |
990 | extern unsigned long int ulabs (long int __x) __THROW __attribute__ ((__const__)) __wur; | |
991 | __extension__ extern unsigned long long int ullabs (long long int __x) | |
992 | __THROW __attribute__ ((__const__)) __wur; | |
993 | #endif | |
28f540f4 | 994 | |
59dd8641 | 995 | /* Return the `div_t', `ldiv_t' or `lldiv_t' representation |
28f540f4 RM |
996 | of the value of NUMER over DENOM. */ |
997 | /* GCC may have built-ins for these someday. */ | |
c1422e5b | 998 | extern div_t div (int __numer, int __denom) |
0476597b | 999 | __THROW __attribute__ ((__const__)) __wur; |
c1422e5b | 1000 | extern ldiv_t ldiv (long int __numer, long int __denom) |
0476597b | 1001 | __THROW __attribute__ ((__const__)) __wur; |
7a5affeb | 1002 | |
ec751a23 | 1003 | #ifdef __USE_ISOC99 |
c1422e5b UD |
1004 | __extension__ extern lldiv_t lldiv (long long int __numer, |
1005 | long long int __denom) | |
0476597b | 1006 | __THROW __attribute__ ((__const__)) __wur; |
59dd8641 | 1007 | #endif |
28f540f4 RM |
1008 | |
1009 | ||
9bde902c | 1010 | #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \ |
498afc54 | 1011 | || defined __USE_MISC |
60478656 RM |
1012 | /* Convert floating point numbers to strings. The returned values are |
1013 | valid only until another call to the same function. */ | |
1014 | ||
1015 | /* Convert VALUE to a string with NDIGIT digits and return a pointer to | |
1016 | this. Set *DECPT with the position of the decimal character and *SIGN | |
1017 | with the sign of the number. */ | |
c1422e5b | 1018 | extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt, |
0476597b | 1019 | int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur; |
60478656 RM |
1020 | |
1021 | /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT | |
1022 | with the position of the decimal character and *SIGN with the sign of | |
1023 | the number. */ | |
c1422e5b | 1024 | extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt, |
0476597b | 1025 | int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur; |
60478656 RM |
1026 | |
1027 | /* If possible convert VALUE to a string with NDIGIT significant digits. | |
1028 | Otherwise use exponential representation. The resulting string will | |
1029 | be written to BUF. */ | |
be27d08c | 1030 | extern char *gcvt (double __value, int __ndigit, char *__buf) |
0476597b | 1031 | __THROW __nonnull ((3)) __wur; |
4220c3ef | 1032 | #endif |
60478656 | 1033 | |
4220c3ef | 1034 | #ifdef __USE_MISC |
2064087b | 1035 | /* Long double versions of above functions. */ |
c1422e5b | 1036 | extern char *qecvt (long double __value, int __ndigit, |
be27d08c | 1037 | int *__restrict __decpt, int *__restrict __sign) |
0476597b | 1038 | __THROW __nonnull ((3, 4)) __wur; |
c1422e5b | 1039 | extern char *qfcvt (long double __value, int __ndigit, |
be27d08c | 1040 | int *__restrict __decpt, int *__restrict __sign) |
0476597b | 1041 | __THROW __nonnull ((3, 4)) __wur; |
be27d08c | 1042 | extern char *qgcvt (long double __value, int __ndigit, char *__buf) |
0476597b | 1043 | __THROW __nonnull ((3)) __wur; |
2064087b RM |
1044 | |
1045 | ||
60478656 RM |
1046 | /* Reentrant version of the functions above which provide their own |
1047 | buffers. */ | |
c1422e5b UD |
1048 | extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt, |
1049 | int *__restrict __sign, char *__restrict __buf, | |
be27d08c | 1050 | size_t __len) __THROW __nonnull ((3, 4, 5)); |
c1422e5b UD |
1051 | extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt, |
1052 | int *__restrict __sign, char *__restrict __buf, | |
be27d08c | 1053 | size_t __len) __THROW __nonnull ((3, 4, 5)); |
c1422e5b UD |
1054 | |
1055 | extern int qecvt_r (long double __value, int __ndigit, | |
1056 | int *__restrict __decpt, int *__restrict __sign, | |
be27d08c UD |
1057 | char *__restrict __buf, size_t __len) |
1058 | __THROW __nonnull ((3, 4, 5)); | |
c1422e5b UD |
1059 | extern int qfcvt_r (long double __value, int __ndigit, |
1060 | int *__restrict __decpt, int *__restrict __sign, | |
be27d08c UD |
1061 | char *__restrict __buf, size_t __len) |
1062 | __THROW __nonnull ((3, 4, 5)); | |
4220c3ef | 1063 | #endif /* misc */ |
60478656 RM |
1064 | |
1065 | ||
28f540f4 RM |
1066 | /* Return the length of the multibyte character |
1067 | in S, which is no longer than N. */ | |
a065ceff | 1068 | extern int mblen (const char *__s, size_t __n) __THROW; |
28f540f4 RM |
1069 | /* Return the length of the given multibyte character, |
1070 | putting its `wchar_t' representation in *PWC. */ | |
c1422e5b | 1071 | extern int mbtowc (wchar_t *__restrict __pwc, |
a065ceff | 1072 | const char *__restrict __s, size_t __n) __THROW; |
28f540f4 RM |
1073 | /* Put the multibyte character represented |
1074 | by WCHAR in S, returning its length. */ | |
a065ceff | 1075 | extern int wctomb (char *__s, wchar_t __wchar) __THROW; |
28f540f4 | 1076 | |
28f540f4 RM |
1077 | |
1078 | /* Convert a multibyte string to a wide char string. */ | |
c1422e5b | 1079 | extern size_t mbstowcs (wchar_t *__restrict __pwcs, |
06febd8c | 1080 | const char *__restrict __s, size_t __n) __THROW |
61af4bbb | 1081 | __attr_access ((__read_only__, 2)); |
28f540f4 | 1082 | /* Convert a wide char string to multibyte string. */ |
c1422e5b | 1083 | extern size_t wcstombs (char *__restrict __s, |
a784e502 | 1084 | const wchar_t *__restrict __pwcs, size_t __n) |
06febd8c | 1085 | __THROW |
e938c027 SP |
1086 | __fortified_attr_access (__write_only__, 1, 3) |
1087 | __attr_access ((__read_only__, 2)); | |
28f540f4 | 1088 | |
498afc54 | 1089 | #ifdef __USE_MISC |
857fa1b8 RM |
1090 | /* Determine whether the string value of RESPONSE matches the affirmation |
1091 | or negative response expression as specified by the LC_MESSAGES category | |
1092 | in the program's current locale. Returns 1 if affirmative, 0 if | |
1093 | negative, and -1 if not matching. */ | |
a784e502 | 1094 | extern int rpmatch (const char *__response) __THROW __nonnull ((1)) __wur; |
857fa1b8 RM |
1095 | #endif |
1096 | ||
1097 | ||
f095bb72 | 1098 | #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 |
2064087b RM |
1099 | /* Parse comma separated suboption from *OPTIONP and match against |
1100 | strings in TOKENS. If found return index and set *VALUEP to | |
1101 | optional value introduced by an equal sign. If the suboption is | |
1102 | not part of TOKENS return in *VALUEP beginning of unknown | |
1103 | suboption. On exit *OPTIONP is set to the beginning of the next | |
2604afb1 | 1104 | token or at the terminating NUL character. */ |
c1422e5b | 1105 | extern int getsubopt (char **__restrict __optionp, |
a784e502 | 1106 | char *const *__restrict __tokens, |
be27d08c | 1107 | char **__restrict __valuep) |
0476597b | 1108 | __THROW __nonnull ((1, 2, 3)) __wur; |
2064087b RM |
1109 | #endif |
1110 | ||
1111 | ||
6591c335 UD |
1112 | /* X/Open pseudo terminal handling. */ |
1113 | ||
f095bb72 | 1114 | #ifdef __USE_XOPEN2KXSI |
0101a56f | 1115 | /* Return a master pseudo-terminal handle. */ |
0476597b | 1116 | extern int posix_openpt (int __oflag) __wur; |
0101a56f UD |
1117 | #endif |
1118 | ||
0014680d | 1119 | #ifdef __USE_XOPEN_EXTENDED |
6591c335 UD |
1120 | /* The next four functions all take a master pseudo-tty fd and |
1121 | perform an operation on the associated slave: */ | |
1122 | ||
1123 | /* Chown the slave to the calling user. */ | |
c1422e5b | 1124 | extern int grantpt (int __fd) __THROW; |
6591c335 UD |
1125 | |
1126 | /* Release an internal lock so the slave can be opened. | |
1127 | Call after grantpt(). */ | |
c1422e5b | 1128 | extern int unlockpt (int __fd) __THROW; |
6591c335 | 1129 | |
6f65e668 | 1130 | /* Return the pathname of the pseudo terminal slave associated with |
4bca4c17 UD |
1131 | the master FD is open on, or NULL on errors. |
1132 | The returned storage is good until the next call to this function. */ | |
0476597b | 1133 | extern char *ptsname (int __fd) __THROW __wur; |
2c6fe0bd UD |
1134 | #endif |
1135 | ||
6591c335 | 1136 | #ifdef __USE_GNU |
4bca4c17 UD |
1137 | /* Store at most BUFLEN characters of the pathname of the slave pseudo |
1138 | terminal associated with the master FD is open on in BUF. | |
1139 | Return 0 on success, otherwise an error number. */ | |
be27d08c | 1140 | extern int ptsname_r (int __fd, char *__buf, size_t __buflen) |
e938c027 | 1141 | __THROW __nonnull ((2)) __fortified_attr_access (__write_only__, 2, 3); |
6591c335 | 1142 | |
4bca4c17 | 1143 | /* Open a master pseudo terminal and return its file descriptor. */ |
f1c30c98 | 1144 | extern int getpt (void); |
6591c335 | 1145 | #endif |
2c6fe0bd | 1146 | |
498afc54 | 1147 | #ifdef __USE_MISC |
b2277c15 RM |
1148 | /* Put the 1 minute, 5 minute and 15 minute load averages into the first |
1149 | NELEM elements of LOADAVG. Return the number written (never more than | |
1150 | three, but may be less than NELEM), or -1 if an error occurred. */ | |
be27d08c UD |
1151 | extern int getloadavg (double __loadavg[], int __nelem) |
1152 | __THROW __nonnull ((1)); | |
b2277c15 RM |
1153 | #endif |
1154 | ||
4242d968 JM |
1155 | #if defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K |
1156 | /* Return the index into the active-logins file (utmp) for | |
1157 | the controlling terminal. */ | |
1158 | extern int ttyslot (void) __THROW; | |
1159 | #endif | |
1160 | ||
f62c8abc | 1161 | #include <bits/stdlib-float.h> |
b799f91d UD |
1162 | |
1163 | /* Define some macros helping to catch buffer overflows. */ | |
5ac3ea17 | 1164 | #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function |
b799f91d UD |
1165 | # include <bits/stdlib.h> |
1166 | #endif | |
e4a39992 GG |
1167 | |
1168 | #include <bits/floatn.h> | |
e2239af3 | 1169 | #if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 |
c6251f03 RM |
1170 | # include <bits/stdlib-ldbl.h> |
1171 | #endif | |
b799f91d | 1172 | |
28f540f4 RM |
1173 | __END_DECLS |
1174 | ||
1175 | #endif /* stdlib.h */ |