localedata: fix weekdays in mdf_RU locale
[glibc.git] / stdlib / stdlib.h
blob901926e8930e305178a06ef11952a7d66814db7a
1 /* Copyright (C) 1991-2024 Free Software Foundation, Inc.
2 Copyright The GNU Toolchain Authors.
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 <https://www.gnu.org/licenses/>. */
20 * ISO C99 Standard: 7.20 General utilities <stdlib.h>
23 #ifndef _STDLIB_H
25 #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
26 #include <bits/libc-header-start.h>
28 /* Get size_t, wchar_t and NULL from <stddef.h>. */
29 #define __need_size_t
30 #define __need_wchar_t
31 #define __need_NULL
32 #include <stddef.h>
34 __BEGIN_DECLS
36 #define _STDLIB_H 1
38 #if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H
39 /* XPG requires a few symbols from <sys/wait.h> being defined. */
40 # include <bits/waitflags.h>
41 # include <bits/waitstatus.h>
43 /* Define the macros <sys/wait.h> also would define this way. */
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)
50 # ifdef __WIFCONTINUED
51 # define WIFCONTINUED(status) __WIFCONTINUED (status)
52 # endif
53 #endif /* X/Open or XPG7 and <sys/wait.h> not included. */
55 /* _FloatN API tests for enablement. */
56 #include <bits/floatn.h>
58 /* Returned by `div'. */
59 typedef struct
61 int quot; /* Quotient. */
62 int rem; /* Remainder. */
63 } div_t;
65 /* Returned by `ldiv'. */
66 #ifndef __ldiv_t_defined
67 typedef struct
69 long int quot; /* Quotient. */
70 long int rem; /* Remainder. */
71 } ldiv_t;
72 # define __ldiv_t_defined 1
73 #endif
75 #if defined __USE_ISOC99 && !defined __lldiv_t_defined
76 /* Returned by `lldiv'. */
77 __extension__ typedef struct
79 long long int quot; /* Quotient. */
80 long long int rem; /* Remainder. */
81 } lldiv_t;
82 # define __lldiv_t_defined 1
83 #endif
86 /* The largest number rand will return (same as INT_MAX). */
87 #define RAND_MAX 2147483647
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. */
96 /* Maximum length of a multibyte character in the current locale. */
97 #define MB_CUR_MAX (__ctype_get_mb_cur_max ())
98 extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
101 /* Convert a string to a floating-point number. */
102 extern double atof (const char *__nptr)
103 __THROW __attribute_pure__ __nonnull ((1)) __wur;
104 /* Convert a string to an integer. */
105 extern int atoi (const char *__nptr)
106 __THROW __attribute_pure__ __nonnull ((1)) __wur;
107 /* Convert a string to a long integer. */
108 extern long int atol (const char *__nptr)
109 __THROW __attribute_pure__ __nonnull ((1)) __wur;
111 #ifdef __USE_ISOC99
112 /* Convert a string to a long long integer. */
113 __extension__ extern long long int atoll (const char *__nptr)
114 __THROW __attribute_pure__ __nonnull ((1)) __wur;
115 #endif
117 /* Convert a string to a floating-point number. */
118 extern double strtod (const char *__restrict __nptr,
119 char **__restrict __endptr)
120 __THROW __nonnull ((1));
122 #ifdef __USE_ISOC99
123 /* Likewise for `float' and `long double' sizes of floating-point numbers. */
124 extern float strtof (const char *__restrict __nptr,
125 char **__restrict __endptr) __THROW __nonnull ((1));
127 extern long double strtold (const char *__restrict __nptr,
128 char **__restrict __endptr)
129 __THROW __nonnull ((1));
130 #endif
132 /* Likewise for '_FloatN' and '_FloatNx'. */
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
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
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
152 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
153 extern _Float128 strtof128 (const char *__restrict __nptr,
154 char **__restrict __endptr)
155 __THROW __nonnull ((1));
156 #endif
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
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
170 #if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
171 extern _Float128x strtof128x (const char *__restrict __nptr,
172 char **__restrict __endptr)
173 __THROW __nonnull ((1));
174 #endif
176 /* Convert a string to a long integer. */
177 extern long int strtol (const char *__restrict __nptr,
178 char **__restrict __endptr, int __base)
179 __THROW __nonnull ((1));
180 /* Convert a string to an unsigned long integer. */
181 extern unsigned long int strtoul (const char *__restrict __nptr,
182 char **__restrict __endptr, int __base)
183 __THROW __nonnull ((1));
185 #ifdef __USE_MISC
186 /* Convert a string to a quadword integer. */
187 __extension__
188 extern long long int strtoq (const char *__restrict __nptr,
189 char **__restrict __endptr, int __base)
190 __THROW __nonnull ((1));
191 /* Convert a string to an unsigned quadword integer. */
192 __extension__
193 extern unsigned long long int strtouq (const char *__restrict __nptr,
194 char **__restrict __endptr, int __base)
195 __THROW __nonnull ((1));
196 #endif /* Use misc. */
198 #ifdef __USE_ISOC99
199 /* Convert a string to a quadword integer. */
200 __extension__
201 extern long long int strtoll (const char *__restrict __nptr,
202 char **__restrict __endptr, int __base)
203 __THROW __nonnull ((1));
204 /* Convert a string to an unsigned quadword integer. */
205 __extension__
206 extern unsigned long long int strtoull (const char *__restrict __nptr,
207 char **__restrict __endptr, int __base)
208 __THROW __nonnull ((1));
209 #endif /* ISO C99 or use MISC. */
211 /* Versions of the above functions that handle '0b' and '0B' prefixes
212 in base 0 or 2. */
213 #if __GLIBC_USE (C23_STRTOL)
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
276 /* Convert a floating-point number to a string. */
277 #if __GLIBC_USE (IEC_60559_BFP_EXT_C23)
278 extern int strfromd (char *__dest, size_t __size, const char *__format,
279 double __f)
280 __THROW __nonnull ((3));
282 extern int strfromf (char *__dest, size_t __size, const char *__format,
283 float __f)
284 __THROW __nonnull ((3));
286 extern int strfroml (char *__dest, size_t __size, const char *__format,
287 long double __f)
288 __THROW __nonnull ((3));
289 #endif
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
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
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
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
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
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
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
334 #ifdef __USE_GNU
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>
340 extern long int strtol_l (const char *__restrict __nptr,
341 char **__restrict __endptr, int __base,
342 locale_t __loc) __THROW __nonnull ((1, 4));
344 extern unsigned long int strtoul_l (const char *__restrict __nptr,
345 char **__restrict __endptr,
346 int __base, locale_t __loc)
347 __THROW __nonnull ((1, 4));
349 __extension__
350 extern long long int strtoll_l (const char *__restrict __nptr,
351 char **__restrict __endptr, int __base,
352 locale_t __loc)
353 __THROW __nonnull ((1, 4));
355 __extension__
356 extern unsigned long long int strtoull_l (const char *__restrict __nptr,
357 char **__restrict __endptr,
358 int __base, locale_t __loc)
359 __THROW __nonnull ((1, 4));
361 /* Versions of the above functions that handle '0b' and '0B' prefixes
362 in base 0 or 2. */
363 # if __GLIBC_USE (C23_STRTOL)
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
415 extern double strtod_l (const char *__restrict __nptr,
416 char **__restrict __endptr, locale_t __loc)
417 __THROW __nonnull ((1, 3));
419 extern float strtof_l (const char *__restrict __nptr,
420 char **__restrict __endptr, locale_t __loc)
421 __THROW __nonnull ((1, 3));
423 extern long double strtold_l (const char *__restrict __nptr,
424 char **__restrict __endptr,
425 locale_t __loc)
426 __THROW __nonnull ((1, 3));
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
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
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
449 # if __HAVE_FLOAT128
450 extern _Float128 strtof128_l (const char *__restrict __nptr,
451 char **__restrict __endptr,
452 locale_t __loc)
453 __THROW __nonnull ((1, 3));
454 # endif
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
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
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
476 #endif /* GNU */
479 #ifdef __USE_EXTERN_INLINES
480 __extern_inline int
481 __NTH (atoi (const char *__nptr))
483 return (int) strtol (__nptr, (char **) NULL, 10);
485 __extern_inline long int
486 __NTH (atol (const char *__nptr))
488 return strtol (__nptr, (char **) NULL, 10);
491 # ifdef __USE_ISOC99
492 __extension__ __extern_inline long long int
493 __NTH (atoll (const char *__nptr))
495 return strtoll (__nptr, (char **) NULL, 10);
497 # endif
498 #endif /* Optimizing and Inlining. */
501 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
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. */
505 extern char *l64a (long int __n) __THROW __wur;
507 /* Read a number from a string S in base 64 as above. */
508 extern long int a64l (const char *__s)
509 __THROW __attribute_pure__ __nonnull ((1)) __wur;
511 #endif /* Use misc || extended X/Open. */
513 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
514 # include <sys/types.h> /* we need int32_t... */
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. */
520 /* Return a random long integer between 0 and 2^31-1 inclusive. */
521 extern long int random (void) __THROW;
523 /* Seed the random number generator with the given number. */
524 extern void srandom (unsigned int __seed) __THROW;
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. */
530 extern char *initstate (unsigned int __seed, char *__statebuf,
531 size_t __statelen) __THROW __nonnull ((2));
533 /* Switch the random number generator to state buffer STATEBUF,
534 which should have been previously initialized by `initstate'. */
535 extern char *setstate (char *__statebuf) __THROW __nonnull ((1));
538 # ifdef __USE_MISC
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. */
543 struct random_data
545 int32_t *fptr; /* Front pointer. */
546 int32_t *rptr; /* Rear pointer. */
547 int32_t *state; /* Array of state values. */
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. */
551 int32_t *end_ptr; /* Pointer behind state table. */
554 extern int random_r (struct random_data *__restrict __buf,
555 int32_t *__restrict __result) __THROW __nonnull ((1, 2));
557 extern int srandom_r (unsigned int __seed, struct random_data *__buf)
558 __THROW __nonnull ((2));
560 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
561 size_t __statelen,
562 struct random_data *__restrict __buf)
563 __THROW __nonnull ((2, 4));
565 extern int setstate_r (char *__restrict __statebuf,
566 struct random_data *__restrict __buf)
567 __THROW __nonnull ((1, 2));
568 # endif /* Use misc. */
569 #endif /* Use extended X/Open || misc. */
572 /* Return a random integer between 0 and RAND_MAX inclusive. */
573 extern int rand (void) __THROW;
574 /* Seed the random number generator with the given number. */
575 extern void srand (unsigned int __seed) __THROW;
577 #ifdef __USE_POSIX199506
578 /* Reentrant interface according to POSIX.1. */
579 extern int rand_r (unsigned int *__seed) __THROW;
580 #endif
583 #if defined __USE_MISC || defined __USE_XOPEN
584 /* System V style 48-bit random number generator functions. */
586 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
587 extern double drand48 (void) __THROW;
588 extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1));
590 /* Return non-negative, long integer in [0,2^31). */
591 extern long int lrand48 (void) __THROW;
592 extern long int nrand48 (unsigned short int __xsubi[3])
593 __THROW __nonnull ((1));
595 /* Return signed, long integers in [-2^31,2^31). */
596 extern long int mrand48 (void) __THROW;
597 extern long int jrand48 (unsigned short int __xsubi[3])
598 __THROW __nonnull ((1));
600 /* Seed random number generator. */
601 extern void srand48 (long int __seedval) __THROW;
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));
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. */
610 struct drand48_data
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. */
616 __extension__ unsigned long long int __a; /* Factor in congruential
617 formula. */
620 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
621 extern int drand48_r (struct drand48_data *__restrict __buffer,
622 double *__restrict __result) __THROW __nonnull ((1, 2));
623 extern int erand48_r (unsigned short int __xsubi[3],
624 struct drand48_data *__restrict __buffer,
625 double *__restrict __result) __THROW __nonnull ((1, 2));
627 /* Return non-negative, long integer in [0,2^31). */
628 extern int lrand48_r (struct drand48_data *__restrict __buffer,
629 long int *__restrict __result)
630 __THROW __nonnull ((1, 2));
631 extern int nrand48_r (unsigned short int __xsubi[3],
632 struct drand48_data *__restrict __buffer,
633 long int *__restrict __result)
634 __THROW __nonnull ((1, 2));
636 /* Return signed, long integers in [-2^31,2^31). */
637 extern int mrand48_r (struct drand48_data *__restrict __buffer,
638 long int *__restrict __result)
639 __THROW __nonnull ((1, 2));
640 extern int jrand48_r (unsigned short int __xsubi[3],
641 struct drand48_data *__restrict __buffer,
642 long int *__restrict __result)
643 __THROW __nonnull ((1, 2));
645 /* Seed random number generator. */
646 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
647 __THROW __nonnull ((2));
649 extern int seed48_r (unsigned short int __seed16v[3],
650 struct drand48_data *__buffer) __THROW __nonnull ((1, 2));
652 extern int lcong48_r (unsigned short int __param[7],
653 struct drand48_data *__buffer)
654 __THROW __nonnull ((1, 2));
656 /* Return a random integer between zero and 2**32-1 (inclusive). */
657 extern __uint32_t arc4random (void)
658 __THROW __wur;
660 /* Fill the buffer with random data. */
661 extern void arc4random_buf (void *__buf, size_t __size)
662 __THROW __nonnull ((1));
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;
668 # endif /* Use misc. */
669 #endif /* Use misc or X/Open. */
671 /* Allocate SIZE bytes of memory. */
672 extern void *malloc (size_t __size) __THROW __attribute_malloc__
673 __attribute_alloc_size__ ((1)) __wur;
674 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
675 extern void *calloc (size_t __nmemb, size_t __size)
676 __THROW __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __wur;
678 /* Re-allocate the previously allocated block
679 in PTR, making the new block SIZE bytes long. */
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. */
683 extern void *realloc (void *__ptr, size_t __size)
684 __THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2));
686 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
687 extern void free (void *__ptr) __THROW;
689 #ifdef __USE_MISC
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)
696 __THROW __attribute_warn_unused_result__
697 __attribute_alloc_size__ ((2, 3))
698 __attr_dealloc_free;
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
705 #ifdef __USE_MISC
706 # include <alloca.h>
707 #endif /* Use misc. */
709 #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \
710 || defined __USE_MISC
711 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
712 extern void *valloc (size_t __size) __THROW __attribute_malloc__
713 __attribute_alloc_size__ ((1)) __wur;
714 #endif
716 #ifdef __USE_XOPEN2K
717 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
718 extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
719 __THROW __nonnull ((1)) __wur;
720 #endif
722 #ifdef __USE_ISOC11
723 /* ISO C variant of aligned allocation. */
724 extern void *aligned_alloc (size_t __alignment, size_t __size)
725 __THROW __attribute_malloc__ __attribute_alloc_align__ ((1))
726 __attribute_alloc_size__ ((2)) __wur;
727 #endif
729 /* Abort execution and generate a core-dump. */
730 extern void abort (void) __THROW __attribute__ ((__noreturn__));
733 /* Register a function to be called when `exit' is called. */
734 extern int atexit (void (*__func) (void)) __THROW __nonnull ((1));
736 #if defined __USE_ISOC11 || defined __USE_ISOCXX11
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
746 #ifdef __USE_MISC
747 /* Register a function to be called with the status
748 given to `exit' and the given argument. */
749 extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
750 __THROW __nonnull ((1));
751 #endif
753 /* Call all functions registered with `atexit' and `on_exit',
754 in the reverse of the order in which they were registered,
755 perform stdio cleanup, and terminate program execution with STATUS. */
756 extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
758 #if defined __USE_ISOC11 || defined __USE_ISOCXX11
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
765 #ifdef __USE_ISOC99
766 /* Terminate the program with STATUS without calling any of the
767 functions registered with `atexit' or `on_exit'. */
768 extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
769 #endif
772 /* Return the value of envariable NAME, or NULL if it doesn't exist. */
773 extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;
775 #ifdef __USE_GNU
776 /* This function is similar to the above but returns NULL if the
777 programs is running with SUID or SGID enabled. */
778 extern char *secure_getenv (const char *__name)
779 __THROW __nonnull ((1)) __wur;
780 #endif
782 #if defined __USE_MISC || defined __USE_XOPEN
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. */
786 extern int putenv (char *__string) __THROW __nonnull ((1));
787 #endif
789 #ifdef __USE_XOPEN2K
790 /* Set NAME to VALUE in the environment.
791 If REPLACE is nonzero, overwrite an existing value. */
792 extern int setenv (const char *__name, const char *__value, int __replace)
793 __THROW __nonnull ((2));
795 /* Remove the variable NAME from the environment. */
796 extern int unsetenv (const char *__name) __THROW __nonnull ((1));
797 #endif
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. */
803 extern int clearenv (void) __THROW;
804 #endif
807 #if defined __USE_MISC \
808 || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8)
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.
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));
815 #endif
817 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
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,
822 or -1 if it cannot create a uniquely-named file.
824 This function is a possible cancellation point and therefore not
825 marked with __THROW. */
826 # ifndef __USE_FILE_OFFSET64
827 extern int mkstemp (char *__template) __nonnull ((1)) __wur;
828 # else
829 # ifdef __REDIRECT
830 extern int __REDIRECT (mkstemp, (char *__template), mkstemp64)
831 __nonnull ((1)) __wur;
832 # else
833 # define mkstemp mkstemp64
834 # endif
835 # endif
836 # ifdef __USE_LARGEFILE64
837 extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
838 # endif
839 #endif
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.
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
864 #ifdef __USE_XOPEN2K8
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. */
870 extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
871 #endif
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..
878 This function is a possible cancellation point and therefore not
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
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.
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
916 #endif
919 /* Execute the given line as a shell command.
921 This function is a cancellation point and therefore not marked with
922 __THROW. */
923 extern int system (const char *__command) __wur;
926 #ifdef __USE_GNU
927 /* Return a malloc'd string containing the canonical absolute name of the
928 existing named file. */
929 extern char *canonicalize_file_name (const char *__name)
930 __THROW __nonnull ((1)) __attribute_malloc__
931 __attr_dealloc_free __wur;
932 #endif
934 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
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. */
940 extern char *realpath (const char *__restrict __name,
941 char *__restrict __resolved) __THROW __wur;
942 #endif
945 /* Shorthand for type of comparison functions. */
946 #ifndef __COMPAR_FN_T
947 # define __COMPAR_FN_T
948 typedef int (*__compar_fn_t) (const void *, const void *);
950 # ifdef __USE_GNU
951 typedef __compar_fn_t comparison_fn_t;
952 # endif
953 #endif
954 #ifdef __USE_GNU
955 typedef int (*__compar_d_fn_t) (const void *, const void *, void *);
956 #endif
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. */
960 extern void *bsearch (const void *__key, const void *__base,
961 size_t __nmemb, size_t __size, __compar_fn_t __compar)
962 __nonnull ((1, 2, 5)) __wur;
964 #ifdef __USE_EXTERN_INLINES
965 # include <bits/stdlib-bsearch.h>
966 #endif
968 /* Sort NMEMB elements of BASE, of SIZE bytes each,
969 using COMPAR to perform the comparisons. */
970 extern void qsort (void *__base, size_t __nmemb, size_t __size,
971 __compar_fn_t __compar) __nonnull ((1, 4));
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
979 /* Return the absolute value of X. */
980 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
981 extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur;
983 #ifdef __USE_ISOC99
984 __extension__ extern long long int llabs (long long int __x)
985 __THROW __attribute__ ((__const__)) __wur;
986 #endif
989 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
990 of the value of NUMER over DENOM. */
991 /* GCC may have built-ins for these someday. */
992 extern div_t div (int __numer, int __denom)
993 __THROW __attribute__ ((__const__)) __wur;
994 extern ldiv_t ldiv (long int __numer, long int __denom)
995 __THROW __attribute__ ((__const__)) __wur;
997 #ifdef __USE_ISOC99
998 __extension__ extern lldiv_t lldiv (long long int __numer,
999 long long int __denom)
1000 __THROW __attribute__ ((__const__)) __wur;
1001 #endif
1004 #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \
1005 || defined __USE_MISC
1006 /* Convert floating point numbers to strings. The returned values are
1007 valid only until another call to the same function. */
1009 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
1010 this. Set *DECPT with the position of the decimal character and *SIGN
1011 with the sign of the number. */
1012 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
1013 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
1015 /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
1016 with the position of the decimal character and *SIGN with the sign of
1017 the number. */
1018 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
1019 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
1021 /* If possible convert VALUE to a string with NDIGIT significant digits.
1022 Otherwise use exponential representation. The resulting string will
1023 be written to BUF. */
1024 extern char *gcvt (double __value, int __ndigit, char *__buf)
1025 __THROW __nonnull ((3)) __wur;
1026 #endif
1028 #ifdef __USE_MISC
1029 /* Long double versions of above functions. */
1030 extern char *qecvt (long double __value, int __ndigit,
1031 int *__restrict __decpt, int *__restrict __sign)
1032 __THROW __nonnull ((3, 4)) __wur;
1033 extern char *qfcvt (long double __value, int __ndigit,
1034 int *__restrict __decpt, int *__restrict __sign)
1035 __THROW __nonnull ((3, 4)) __wur;
1036 extern char *qgcvt (long double __value, int __ndigit, char *__buf)
1037 __THROW __nonnull ((3)) __wur;
1040 /* Reentrant version of the functions above which provide their own
1041 buffers. */
1042 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
1043 int *__restrict __sign, char *__restrict __buf,
1044 size_t __len) __THROW __nonnull ((3, 4, 5));
1045 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
1046 int *__restrict __sign, char *__restrict __buf,
1047 size_t __len) __THROW __nonnull ((3, 4, 5));
1049 extern int qecvt_r (long double __value, int __ndigit,
1050 int *__restrict __decpt, int *__restrict __sign,
1051 char *__restrict __buf, size_t __len)
1052 __THROW __nonnull ((3, 4, 5));
1053 extern int qfcvt_r (long double __value, int __ndigit,
1054 int *__restrict __decpt, int *__restrict __sign,
1055 char *__restrict __buf, size_t __len)
1056 __THROW __nonnull ((3, 4, 5));
1057 #endif /* misc */
1060 /* Return the length of the multibyte character
1061 in S, which is no longer than N. */
1062 extern int mblen (const char *__s, size_t __n) __THROW;
1063 /* Return the length of the given multibyte character,
1064 putting its `wchar_t' representation in *PWC. */
1065 extern int mbtowc (wchar_t *__restrict __pwc,
1066 const char *__restrict __s, size_t __n) __THROW;
1067 /* Put the multibyte character represented
1068 by WCHAR in S, returning its length. */
1069 extern int wctomb (char *__s, wchar_t __wchar) __THROW;
1072 /* Convert a multibyte string to a wide char string. */
1073 extern size_t mbstowcs (wchar_t *__restrict __pwcs,
1074 const char *__restrict __s, size_t __n) __THROW
1075 __attr_access ((__read_only__, 2));
1076 /* Convert a wide char string to multibyte string. */
1077 extern size_t wcstombs (char *__restrict __s,
1078 const wchar_t *__restrict __pwcs, size_t __n)
1079 __THROW
1080 __fortified_attr_access (__write_only__, 1, 3)
1081 __attr_access ((__read_only__, 2));
1083 #ifdef __USE_MISC
1084 /* Determine whether the string value of RESPONSE matches the affirmation
1085 or negative response expression as specified by the LC_MESSAGES category
1086 in the program's current locale. Returns 1 if affirmative, 0 if
1087 negative, and -1 if not matching. */
1088 extern int rpmatch (const char *__response) __THROW __nonnull ((1)) __wur;
1089 #endif
1092 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
1093 /* Parse comma separated suboption from *OPTIONP and match against
1094 strings in TOKENS. If found return index and set *VALUEP to
1095 optional value introduced by an equal sign. If the suboption is
1096 not part of TOKENS return in *VALUEP beginning of unknown
1097 suboption. On exit *OPTIONP is set to the beginning of the next
1098 token or at the terminating NUL character. */
1099 extern int getsubopt (char **__restrict __optionp,
1100 char *const *__restrict __tokens,
1101 char **__restrict __valuep)
1102 __THROW __nonnull ((1, 2, 3)) __wur;
1103 #endif
1106 /* X/Open pseudo terminal handling. */
1108 #ifdef __USE_XOPEN2KXSI
1109 /* Return a master pseudo-terminal handle. */
1110 extern int posix_openpt (int __oflag) __wur;
1111 #endif
1113 #ifdef __USE_XOPEN_EXTENDED
1114 /* The next four functions all take a master pseudo-tty fd and
1115 perform an operation on the associated slave: */
1117 /* Chown the slave to the calling user. */
1118 extern int grantpt (int __fd) __THROW;
1120 /* Release an internal lock so the slave can be opened.
1121 Call after grantpt(). */
1122 extern int unlockpt (int __fd) __THROW;
1124 /* Return the pathname of the pseudo terminal slave associated with
1125 the master FD is open on, or NULL on errors.
1126 The returned storage is good until the next call to this function. */
1127 extern char *ptsname (int __fd) __THROW __wur;
1128 #endif
1130 #ifdef __USE_GNU
1131 /* Store at most BUFLEN characters of the pathname of the slave pseudo
1132 terminal associated with the master FD is open on in BUF.
1133 Return 0 on success, otherwise an error number. */
1134 extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
1135 __THROW __nonnull ((2)) __fortified_attr_access (__write_only__, 2, 3);
1137 /* Open a master pseudo terminal and return its file descriptor. */
1138 extern int getpt (void);
1139 #endif
1141 #ifdef __USE_MISC
1142 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
1143 NELEM elements of LOADAVG. Return the number written (never more than
1144 three, but may be less than NELEM), or -1 if an error occurred. */
1145 extern int getloadavg (double __loadavg[], int __nelem)
1146 __THROW __nonnull ((1));
1147 #endif
1149 #if defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K
1150 /* Return the index into the active-logins file (utmp) for
1151 the controlling terminal. */
1152 extern int ttyslot (void) __THROW;
1153 #endif
1155 #include <bits/stdlib-float.h>
1157 /* Define some macros helping to catch buffer overflows. */
1158 #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
1159 # include <bits/stdlib.h>
1160 #endif
1162 #include <bits/floatn.h>
1163 #if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
1164 # include <bits/stdlib-ldbl.h>
1165 #endif
1167 __END_DECLS
1169 #endif /* stdlib.h */