Fix another x86 sys/ucontext.h namespace issue (bug 21457).
[glibc.git] / stdlib / stdlib.h
blob6f1e70e254e6d14b50eee2f85b3c5d4669d45917
1 /* Copyright (C) 1991-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
19 * ISO C99 Standard: 7.20 General utilities <stdlib.h>
22 #ifndef _STDLIB_H
24 #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
25 #include <bits/libc-header-start.h>
27 /* Get size_t, wchar_t and NULL from <stddef.h>. */
28 #define __need_size_t
29 #define __need_wchar_t
30 #define __need_NULL
31 #include <stddef.h>
33 __BEGIN_DECLS
35 #define _STDLIB_H 1
37 #if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H
38 /* XPG requires a few symbols from <sys/wait.h> being defined. */
39 # include <bits/waitflags.h>
40 # include <bits/waitstatus.h>
42 /* Define the macros <sys/wait.h> also would define this way. */
43 # define WEXITSTATUS(status) __WEXITSTATUS (status)
44 # define WTERMSIG(status) __WTERMSIG (status)
45 # define WSTOPSIG(status) __WSTOPSIG (status)
46 # define WIFEXITED(status) __WIFEXITED (status)
47 # define WIFSIGNALED(status) __WIFSIGNALED (status)
48 # define WIFSTOPPED(status) __WIFSTOPPED (status)
49 # ifdef __WIFCONTINUED
50 # define WIFCONTINUED(status) __WIFCONTINUED (status)
51 # endif
52 #endif /* X/Open or XPG7 and <sys/wait.h> not included. */
54 /* _FloatN API tests for enablement. */
55 #include <bits/floatn.h>
57 /* Returned by `div'. */
58 typedef struct
60 int quot; /* Quotient. */
61 int rem; /* Remainder. */
62 } div_t;
64 /* Returned by `ldiv'. */
65 #ifndef __ldiv_t_defined
66 typedef struct
68 long int quot; /* Quotient. */
69 long int rem; /* Remainder. */
70 } ldiv_t;
71 # define __ldiv_t_defined 1
72 #endif
74 #if defined __USE_ISOC99 && !defined __lldiv_t_defined
75 /* Returned by `lldiv'. */
76 __extension__ typedef struct
78 long long int quot; /* Quotient. */
79 long long int rem; /* Remainder. */
80 } lldiv_t;
81 # define __lldiv_t_defined 1
82 #endif
85 /* The largest number rand will return (same as INT_MAX). */
86 #define RAND_MAX 2147483647
89 /* We define these the same for all machines.
90 Changes from this to the outside world should be done in `_exit'. */
91 #define EXIT_FAILURE 1 /* Failing exit status. */
92 #define EXIT_SUCCESS 0 /* Successful exit status. */
95 /* Maximum length of a multibyte character in the current locale. */
96 #define MB_CUR_MAX (__ctype_get_mb_cur_max ())
97 extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
100 /* Convert a string to a floating-point number. */
101 extern double atof (const char *__nptr)
102 __THROW __attribute_pure__ __nonnull ((1)) __wur;
103 /* Convert a string to an integer. */
104 extern int atoi (const char *__nptr)
105 __THROW __attribute_pure__ __nonnull ((1)) __wur;
106 /* Convert a string to a long integer. */
107 extern long int atol (const char *__nptr)
108 __THROW __attribute_pure__ __nonnull ((1)) __wur;
110 #ifdef __USE_ISOC99
111 /* Convert a string to a long long integer. */
112 __extension__ extern long long int atoll (const char *__nptr)
113 __THROW __attribute_pure__ __nonnull ((1)) __wur;
114 #endif
116 /* Convert a string to a floating-point number. */
117 extern double strtod (const char *__restrict __nptr,
118 char **__restrict __endptr)
119 __THROW __nonnull ((1));
121 #ifdef __USE_ISOC99
122 /* Likewise for `float' and `long double' sizes of floating-point numbers. */
123 extern float strtof (const char *__restrict __nptr,
124 char **__restrict __endptr) __THROW __nonnull ((1));
126 extern long double strtold (const char *__restrict __nptr,
127 char **__restrict __endptr)
128 __THROW __nonnull ((1));
129 #endif
131 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
132 /* Likewise for the '_Float128' format */
133 extern _Float128 strtof128 (const char *__restrict __nptr,
134 char **__restrict __endptr)
135 __THROW __nonnull ((1));
136 #endif
138 /* Convert a string to a long integer. */
139 extern long int strtol (const char *__restrict __nptr,
140 char **__restrict __endptr, int __base)
141 __THROW __nonnull ((1));
142 /* Convert a string to an unsigned long integer. */
143 extern unsigned long int strtoul (const char *__restrict __nptr,
144 char **__restrict __endptr, int __base)
145 __THROW __nonnull ((1));
147 #ifdef __USE_MISC
148 /* Convert a string to a quadword integer. */
149 __extension__
150 extern long long int strtoq (const char *__restrict __nptr,
151 char **__restrict __endptr, int __base)
152 __THROW __nonnull ((1));
153 /* Convert a string to an unsigned quadword integer. */
154 __extension__
155 extern unsigned long long int strtouq (const char *__restrict __nptr,
156 char **__restrict __endptr, int __base)
157 __THROW __nonnull ((1));
158 #endif /* Use misc. */
160 #ifdef __USE_ISOC99
161 /* Convert a string to a quadword integer. */
162 __extension__
163 extern long long int strtoll (const char *__restrict __nptr,
164 char **__restrict __endptr, int __base)
165 __THROW __nonnull ((1));
166 /* Convert a string to an unsigned quadword integer. */
167 __extension__
168 extern unsigned long long int strtoull (const char *__restrict __nptr,
169 char **__restrict __endptr, int __base)
170 __THROW __nonnull ((1));
171 #endif /* ISO C99 or use MISC. */
173 /* Convert a floating-point number to a string. */
174 #if __GLIBC_USE (IEC_60559_BFP_EXT)
175 extern int strfromd (char *__dest, size_t __size, const char *__format,
176 double __f)
177 __THROW __nonnull ((3));
179 extern int strfromf (char *__dest, size_t __size, const char *__format,
180 float __f)
181 __THROW __nonnull ((3));
183 extern int strfroml (char *__dest, size_t __size, const char *__format,
184 long double __f)
185 __THROW __nonnull ((3));
186 #endif
188 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
189 extern int strfromf128 (char *__dest, size_t __size, const char * __format,
190 _Float128 __f)
191 __THROW __nonnull ((3));
192 #endif
195 #ifdef __USE_GNU
196 /* The concept of one static locale per category is not very well
197 thought out. Many applications will need to process its data using
198 information from several different locales. Another problem is
199 the implementation of the internationalization handling in the
200 ISO C++ standard library. To support this another set of
201 the functions using locale data exist which take an additional
202 argument.
204 Attention: even though several *_l interfaces are part of POSIX:2008,
205 these are not. */
207 /* Structure for reentrant locale using functions. This is an
208 (almost) opaque type for the user level programs. */
209 # include <xlocale.h>
211 /* Special versions of the functions above which take the locale to
212 use as an additional parameter. */
213 extern long int strtol_l (const char *__restrict __nptr,
214 char **__restrict __endptr, int __base,
215 __locale_t __loc) __THROW __nonnull ((1, 4));
217 extern unsigned long int strtoul_l (const char *__restrict __nptr,
218 char **__restrict __endptr,
219 int __base, __locale_t __loc)
220 __THROW __nonnull ((1, 4));
222 __extension__
223 extern long long int strtoll_l (const char *__restrict __nptr,
224 char **__restrict __endptr, int __base,
225 __locale_t __loc)
226 __THROW __nonnull ((1, 4));
228 __extension__
229 extern unsigned long long int strtoull_l (const char *__restrict __nptr,
230 char **__restrict __endptr,
231 int __base, __locale_t __loc)
232 __THROW __nonnull ((1, 4));
234 extern double strtod_l (const char *__restrict __nptr,
235 char **__restrict __endptr, __locale_t __loc)
236 __THROW __nonnull ((1, 3));
238 extern float strtof_l (const char *__restrict __nptr,
239 char **__restrict __endptr, __locale_t __loc)
240 __THROW __nonnull ((1, 3));
242 extern long double strtold_l (const char *__restrict __nptr,
243 char **__restrict __endptr,
244 __locale_t __loc)
245 __THROW __nonnull ((1, 3));
247 # if __HAVE_FLOAT128
248 extern _Float128 strtof128_l (const char *__restrict __nptr,
249 char **__restrict __endptr,
250 __locale_t __loc)
251 __THROW __nonnull ((1, 3));
252 # endif
253 #endif /* GNU */
256 #ifdef __USE_EXTERN_INLINES
257 __extern_inline int
258 __NTH (atoi (const char *__nptr))
260 return (int) strtol (__nptr, (char **) NULL, 10);
262 __extern_inline long int
263 __NTH (atol (const char *__nptr))
265 return strtol (__nptr, (char **) NULL, 10);
268 # ifdef __USE_ISOC99
269 __extension__ __extern_inline long long int
270 __NTH (atoll (const char *__nptr))
272 return strtoll (__nptr, (char **) NULL, 10);
274 # endif
275 #endif /* Optimizing and Inlining. */
278 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
279 /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant
280 digit first. Returns a pointer to static storage overwritten by the
281 next call. */
282 extern char *l64a (long int __n) __THROW __wur;
284 /* Read a number from a string S in base 64 as above. */
285 extern long int a64l (const char *__s)
286 __THROW __attribute_pure__ __nonnull ((1)) __wur;
288 #endif /* Use misc || extended X/Open. */
290 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
291 # include <sys/types.h> /* we need int32_t... */
293 /* These are the functions that actually do things. The `random', `srandom',
294 `initstate' and `setstate' functions are those from BSD Unices.
295 The `rand' and `srand' functions are required by the ANSI standard.
296 We provide both interfaces to the same random number generator. */
297 /* Return a random long integer between 0 and RAND_MAX inclusive. */
298 extern long int random (void) __THROW;
300 /* Seed the random number generator with the given number. */
301 extern void srandom (unsigned int __seed) __THROW;
303 /* Initialize the random number generator to use state buffer STATEBUF,
304 of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
305 32, 64, 128 and 256, the bigger the better; values less than 8 will
306 cause an error and values greater than 256 will be rounded down. */
307 extern char *initstate (unsigned int __seed, char *__statebuf,
308 size_t __statelen) __THROW __nonnull ((2));
310 /* Switch the random number generator to state buffer STATEBUF,
311 which should have been previously initialized by `initstate'. */
312 extern char *setstate (char *__statebuf) __THROW __nonnull ((1));
315 # ifdef __USE_MISC
316 /* Reentrant versions of the `random' family of functions.
317 These functions all use the following data structure to contain
318 state, rather than global state variables. */
320 struct random_data
322 int32_t *fptr; /* Front pointer. */
323 int32_t *rptr; /* Rear pointer. */
324 int32_t *state; /* Array of state values. */
325 int rand_type; /* Type of random number generator. */
326 int rand_deg; /* Degree of random number generator. */
327 int rand_sep; /* Distance between front and rear. */
328 int32_t *end_ptr; /* Pointer behind state table. */
331 extern int random_r (struct random_data *__restrict __buf,
332 int32_t *__restrict __result) __THROW __nonnull ((1, 2));
334 extern int srandom_r (unsigned int __seed, struct random_data *__buf)
335 __THROW __nonnull ((2));
337 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
338 size_t __statelen,
339 struct random_data *__restrict __buf)
340 __THROW __nonnull ((2, 4));
342 extern int setstate_r (char *__restrict __statebuf,
343 struct random_data *__restrict __buf)
344 __THROW __nonnull ((1, 2));
345 # endif /* Use misc. */
346 #endif /* Use extended X/Open || misc. */
349 /* Return a random integer between 0 and RAND_MAX inclusive. */
350 extern int rand (void) __THROW;
351 /* Seed the random number generator with the given number. */
352 extern void srand (unsigned int __seed) __THROW;
354 #ifdef __USE_POSIX199506
355 /* Reentrant interface according to POSIX.1. */
356 extern int rand_r (unsigned int *__seed) __THROW;
357 #endif
360 #if defined __USE_MISC || defined __USE_XOPEN
361 /* System V style 48-bit random number generator functions. */
363 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
364 extern double drand48 (void) __THROW;
365 extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1));
367 /* Return non-negative, long integer in [0,2^31). */
368 extern long int lrand48 (void) __THROW;
369 extern long int nrand48 (unsigned short int __xsubi[3])
370 __THROW __nonnull ((1));
372 /* Return signed, long integers in [-2^31,2^31). */
373 extern long int mrand48 (void) __THROW;
374 extern long int jrand48 (unsigned short int __xsubi[3])
375 __THROW __nonnull ((1));
377 /* Seed random number generator. */
378 extern void srand48 (long int __seedval) __THROW;
379 extern unsigned short int *seed48 (unsigned short int __seed16v[3])
380 __THROW __nonnull ((1));
381 extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1));
383 # ifdef __USE_MISC
384 /* Data structure for communication with thread safe versions. This
385 type is to be regarded as opaque. It's only exported because users
386 have to allocate objects of this type. */
387 struct drand48_data
389 unsigned short int __x[3]; /* Current state. */
390 unsigned short int __old_x[3]; /* Old state. */
391 unsigned short int __c; /* Additive const. in congruential formula. */
392 unsigned short int __init; /* Flag for initializing. */
393 __extension__ unsigned long long int __a; /* Factor in congruential
394 formula. */
397 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
398 extern int drand48_r (struct drand48_data *__restrict __buffer,
399 double *__restrict __result) __THROW __nonnull ((1, 2));
400 extern int erand48_r (unsigned short int __xsubi[3],
401 struct drand48_data *__restrict __buffer,
402 double *__restrict __result) __THROW __nonnull ((1, 2));
404 /* Return non-negative, long integer in [0,2^31). */
405 extern int lrand48_r (struct drand48_data *__restrict __buffer,
406 long int *__restrict __result)
407 __THROW __nonnull ((1, 2));
408 extern int nrand48_r (unsigned short int __xsubi[3],
409 struct drand48_data *__restrict __buffer,
410 long int *__restrict __result)
411 __THROW __nonnull ((1, 2));
413 /* Return signed, long integers in [-2^31,2^31). */
414 extern int mrand48_r (struct drand48_data *__restrict __buffer,
415 long int *__restrict __result)
416 __THROW __nonnull ((1, 2));
417 extern int jrand48_r (unsigned short int __xsubi[3],
418 struct drand48_data *__restrict __buffer,
419 long int *__restrict __result)
420 __THROW __nonnull ((1, 2));
422 /* Seed random number generator. */
423 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
424 __THROW __nonnull ((2));
426 extern int seed48_r (unsigned short int __seed16v[3],
427 struct drand48_data *__buffer) __THROW __nonnull ((1, 2));
429 extern int lcong48_r (unsigned short int __param[7],
430 struct drand48_data *__buffer)
431 __THROW __nonnull ((1, 2));
432 # endif /* Use misc. */
433 #endif /* Use misc or X/Open. */
435 /* Allocate SIZE bytes of memory. */
436 extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
437 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
438 extern void *calloc (size_t __nmemb, size_t __size)
439 __THROW __attribute_malloc__ __wur;
441 /* Re-allocate the previously allocated block
442 in PTR, making the new block SIZE bytes long. */
443 /* __attribute_malloc__ is not used, because if realloc returns
444 the same pointer that was passed to it, aliasing needs to be allowed
445 between objects pointed by the old and new pointers. */
446 extern void *realloc (void *__ptr, size_t __size)
447 __THROW __attribute_warn_unused_result__;
449 #ifdef __USE_GNU
450 /* Re-allocate the previously allocated block in PTR, making the new
451 block large enough for NMEMB elements of SIZE bytes each. */
452 /* __attribute_malloc__ is not used, because if reallocarray returns
453 the same pointer that was passed to it, aliasing needs to be allowed
454 between objects pointed by the old and new pointers. */
455 extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)
456 __THROW __attribute_warn_unused_result__;
457 #endif
459 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
460 extern void free (void *__ptr) __THROW;
462 #ifdef __USE_MISC
463 # include <alloca.h>
464 #endif /* Use misc. */
466 #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \
467 || defined __USE_MISC
468 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
469 extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
470 #endif
472 #ifdef __USE_XOPEN2K
473 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
474 extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
475 __THROW __nonnull ((1)) __wur;
476 #endif
478 #ifdef __USE_ISOC11
479 /* ISO C variant of aligned allocation. */
480 extern void *aligned_alloc (size_t __alignment, size_t __size)
481 __THROW __attribute_malloc__ __attribute_alloc_size__ ((2)) __wur;
482 #endif
484 /* Abort execution and generate a core-dump. */
485 extern void abort (void) __THROW __attribute__ ((__noreturn__));
488 /* Register a function to be called when `exit' is called. */
489 extern int atexit (void (*__func) (void)) __THROW __nonnull ((1));
491 #if defined __USE_ISOC11 || defined __USE_ISOCXX11
492 /* Register a function to be called when `quick_exit' is called. */
493 # ifdef __cplusplus
494 extern "C++" int at_quick_exit (void (*__func) (void))
495 __THROW __asm ("at_quick_exit") __nonnull ((1));
496 # else
497 extern int at_quick_exit (void (*__func) (void)) __THROW __nonnull ((1));
498 # endif
499 #endif
501 #ifdef __USE_MISC
502 /* Register a function to be called with the status
503 given to `exit' and the given argument. */
504 extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
505 __THROW __nonnull ((1));
506 #endif
508 /* Call all functions registered with `atexit' and `on_exit',
509 in the reverse of the order in which they were registered,
510 perform stdio cleanup, and terminate program execution with STATUS. */
511 extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
513 #if defined __USE_ISOC11 || defined __USE_ISOCXX11
514 /* Call all functions registered with `at_quick_exit' in the reverse
515 of the order in which they were registered and terminate program
516 execution with STATUS. */
517 extern void quick_exit (int __status) __THROW __attribute__ ((__noreturn__));
518 #endif
520 #ifdef __USE_ISOC99
521 /* Terminate the program with STATUS without calling any of the
522 functions registered with `atexit' or `on_exit'. */
523 extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
524 #endif
527 /* Return the value of envariable NAME, or NULL if it doesn't exist. */
528 extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;
530 #ifdef __USE_GNU
531 /* This function is similar to the above but returns NULL if the
532 programs is running with SUID or SGID enabled. */
533 extern char *secure_getenv (const char *__name)
534 __THROW __nonnull ((1)) __wur;
535 #endif
537 #if defined __USE_MISC || defined __USE_XOPEN
538 /* The SVID says this is in <stdio.h>, but this seems a better place. */
539 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
540 If there is no `=', remove NAME from the environment. */
541 extern int putenv (char *__string) __THROW __nonnull ((1));
542 #endif
544 #ifdef __USE_XOPEN2K
545 /* Set NAME to VALUE in the environment.
546 If REPLACE is nonzero, overwrite an existing value. */
547 extern int setenv (const char *__name, const char *__value, int __replace)
548 __THROW __nonnull ((2));
550 /* Remove the variable NAME from the environment. */
551 extern int unsetenv (const char *__name) __THROW __nonnull ((1));
552 #endif
554 #ifdef __USE_MISC
555 /* The `clearenv' was planned to be added to POSIX.1 but probably
556 never made it. Nevertheless the POSIX.9 standard (POSIX bindings
557 for Fortran 77) requires this function. */
558 extern int clearenv (void) __THROW;
559 #endif
562 #if defined __USE_MISC \
563 || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8)
564 /* Generate a unique temporary file name from TEMPLATE.
565 The last six characters of TEMPLATE must be "XXXXXX";
566 they are replaced with a string that makes the file name unique.
567 Always returns TEMPLATE, it's either a temporary file name or a null
568 string if it cannot get a unique file name. */
569 extern char *mktemp (char *__template) __THROW __nonnull ((1));
570 #endif
572 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
573 /* Generate a unique temporary file name from TEMPLATE.
574 The last six characters of TEMPLATE must be "XXXXXX";
575 they are replaced with a string that makes the filename unique.
576 Returns a file descriptor open on the file for reading and writing,
577 or -1 if it cannot create a uniquely-named file.
579 This function is a possible cancellation point and therefore not
580 marked with __THROW. */
581 # ifndef __USE_FILE_OFFSET64
582 extern int mkstemp (char *__template) __nonnull ((1)) __wur;
583 # else
584 # ifdef __REDIRECT
585 extern int __REDIRECT (mkstemp, (char *__template), mkstemp64)
586 __nonnull ((1)) __wur;
587 # else
588 # define mkstemp mkstemp64
589 # endif
590 # endif
591 # ifdef __USE_LARGEFILE64
592 extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
593 # endif
594 #endif
596 #ifdef __USE_MISC
597 /* Similar to mkstemp, but the template can have a suffix after the
598 XXXXXX. The length of the suffix is specified in the second
599 parameter.
601 This function is a possible cancellation point and therefore not
602 marked with __THROW. */
603 # ifndef __USE_FILE_OFFSET64
604 extern int mkstemps (char *__template, int __suffixlen) __nonnull ((1)) __wur;
605 # else
606 # ifdef __REDIRECT
607 extern int __REDIRECT (mkstemps, (char *__template, int __suffixlen),
608 mkstemps64) __nonnull ((1)) __wur;
609 # else
610 # define mkstemps mkstemps64
611 # endif
612 # endif
613 # ifdef __USE_LARGEFILE64
614 extern int mkstemps64 (char *__template, int __suffixlen)
615 __nonnull ((1)) __wur;
616 # endif
617 #endif
619 #ifdef __USE_XOPEN2K8
620 /* Create a unique temporary directory from TEMPLATE.
621 The last six characters of TEMPLATE must be "XXXXXX";
622 they are replaced with a string that makes the directory name unique.
623 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
624 The directory is created mode 700. */
625 extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
626 #endif
628 #ifdef __USE_GNU
629 /* Generate a unique temporary file name from TEMPLATE similar to
630 mkstemp. But allow the caller to pass additional flags which are
631 used in the open call to create the file..
633 This function is a possible cancellation point and therefore not
634 marked with __THROW. */
635 # ifndef __USE_FILE_OFFSET64
636 extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur;
637 # else
638 # ifdef __REDIRECT
639 extern int __REDIRECT (mkostemp, (char *__template, int __flags), mkostemp64)
640 __nonnull ((1)) __wur;
641 # else
642 # define mkostemp mkostemp64
643 # endif
644 # endif
645 # ifdef __USE_LARGEFILE64
646 extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur;
647 # endif
649 /* Similar to mkostemp, but the template can have a suffix after the
650 XXXXXX. The length of the suffix is specified in the second
651 parameter.
653 This function is a possible cancellation point and therefore not
654 marked with __THROW. */
655 # ifndef __USE_FILE_OFFSET64
656 extern int mkostemps (char *__template, int __suffixlen, int __flags)
657 __nonnull ((1)) __wur;
658 # else
659 # ifdef __REDIRECT
660 extern int __REDIRECT (mkostemps, (char *__template, int __suffixlen,
661 int __flags), mkostemps64)
662 __nonnull ((1)) __wur;
663 # else
664 # define mkostemps mkostemps64
665 # endif
666 # endif
667 # ifdef __USE_LARGEFILE64
668 extern int mkostemps64 (char *__template, int __suffixlen, int __flags)
669 __nonnull ((1)) __wur;
670 # endif
671 #endif
674 /* Execute the given line as a shell command.
676 This function is a cancellation point and therefore not marked with
677 __THROW. */
678 extern int system (const char *__command) __wur;
681 #ifdef __USE_GNU
682 /* Return a malloc'd string containing the canonical absolute name of the
683 existing named file. */
684 extern char *canonicalize_file_name (const char *__name)
685 __THROW __nonnull ((1)) __wur;
686 #endif
688 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
689 /* Return the canonical absolute name of file NAME. If RESOLVED is
690 null, the result is malloc'd; otherwise, if the canonical name is
691 PATH_MAX chars or more, returns null with `errno' set to
692 ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
693 returns the name in RESOLVED. */
694 extern char *realpath (const char *__restrict __name,
695 char *__restrict __resolved) __THROW __wur;
696 #endif
699 /* Shorthand for type of comparison functions. */
700 #ifndef __COMPAR_FN_T
701 # define __COMPAR_FN_T
702 typedef int (*__compar_fn_t) (const void *, const void *);
704 # ifdef __USE_GNU
705 typedef __compar_fn_t comparison_fn_t;
706 # endif
707 #endif
708 #ifdef __USE_GNU
709 typedef int (*__compar_d_fn_t) (const void *, const void *, void *);
710 #endif
712 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
713 of SIZE bytes each, using COMPAR to perform the comparisons. */
714 extern void *bsearch (const void *__key, const void *__base,
715 size_t __nmemb, size_t __size, __compar_fn_t __compar)
716 __nonnull ((1, 2, 5)) __wur;
718 #ifdef __USE_EXTERN_INLINES
719 # include <bits/stdlib-bsearch.h>
720 #endif
722 /* Sort NMEMB elements of BASE, of SIZE bytes each,
723 using COMPAR to perform the comparisons. */
724 extern void qsort (void *__base, size_t __nmemb, size_t __size,
725 __compar_fn_t __compar) __nonnull ((1, 4));
726 #ifdef __USE_GNU
727 extern void qsort_r (void *__base, size_t __nmemb, size_t __size,
728 __compar_d_fn_t __compar, void *__arg)
729 __nonnull ((1, 4));
730 #endif
733 /* Return the absolute value of X. */
734 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
735 extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur;
737 #ifdef __USE_ISOC99
738 __extension__ extern long long int llabs (long long int __x)
739 __THROW __attribute__ ((__const__)) __wur;
740 #endif
743 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
744 of the value of NUMER over DENOM. */
745 /* GCC may have built-ins for these someday. */
746 extern div_t div (int __numer, int __denom)
747 __THROW __attribute__ ((__const__)) __wur;
748 extern ldiv_t ldiv (long int __numer, long int __denom)
749 __THROW __attribute__ ((__const__)) __wur;
751 #ifdef __USE_ISOC99
752 __extension__ extern lldiv_t lldiv (long long int __numer,
753 long long int __denom)
754 __THROW __attribute__ ((__const__)) __wur;
755 #endif
758 #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \
759 || defined __USE_MISC
760 /* Convert floating point numbers to strings. The returned values are
761 valid only until another call to the same function. */
763 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
764 this. Set *DECPT with the position of the decimal character and *SIGN
765 with the sign of the number. */
766 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
767 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
769 /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
770 with the position of the decimal character and *SIGN with the sign of
771 the number. */
772 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
773 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
775 /* If possible convert VALUE to a string with NDIGIT significant digits.
776 Otherwise use exponential representation. The resulting string will
777 be written to BUF. */
778 extern char *gcvt (double __value, int __ndigit, char *__buf)
779 __THROW __nonnull ((3)) __wur;
780 #endif
782 #ifdef __USE_MISC
783 /* Long double versions of above functions. */
784 extern char *qecvt (long double __value, int __ndigit,
785 int *__restrict __decpt, int *__restrict __sign)
786 __THROW __nonnull ((3, 4)) __wur;
787 extern char *qfcvt (long double __value, int __ndigit,
788 int *__restrict __decpt, int *__restrict __sign)
789 __THROW __nonnull ((3, 4)) __wur;
790 extern char *qgcvt (long double __value, int __ndigit, char *__buf)
791 __THROW __nonnull ((3)) __wur;
794 /* Reentrant version of the functions above which provide their own
795 buffers. */
796 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
797 int *__restrict __sign, char *__restrict __buf,
798 size_t __len) __THROW __nonnull ((3, 4, 5));
799 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
800 int *__restrict __sign, char *__restrict __buf,
801 size_t __len) __THROW __nonnull ((3, 4, 5));
803 extern int qecvt_r (long double __value, int __ndigit,
804 int *__restrict __decpt, int *__restrict __sign,
805 char *__restrict __buf, size_t __len)
806 __THROW __nonnull ((3, 4, 5));
807 extern int qfcvt_r (long double __value, int __ndigit,
808 int *__restrict __decpt, int *__restrict __sign,
809 char *__restrict __buf, size_t __len)
810 __THROW __nonnull ((3, 4, 5));
811 #endif /* misc */
814 /* Return the length of the multibyte character
815 in S, which is no longer than N. */
816 extern int mblen (const char *__s, size_t __n) __THROW;
817 /* Return the length of the given multibyte character,
818 putting its `wchar_t' representation in *PWC. */
819 extern int mbtowc (wchar_t *__restrict __pwc,
820 const char *__restrict __s, size_t __n) __THROW;
821 /* Put the multibyte character represented
822 by WCHAR in S, returning its length. */
823 extern int wctomb (char *__s, wchar_t __wchar) __THROW;
826 /* Convert a multibyte string to a wide char string. */
827 extern size_t mbstowcs (wchar_t *__restrict __pwcs,
828 const char *__restrict __s, size_t __n) __THROW;
829 /* Convert a wide char string to multibyte string. */
830 extern size_t wcstombs (char *__restrict __s,
831 const wchar_t *__restrict __pwcs, size_t __n)
832 __THROW;
835 #ifdef __USE_MISC
836 /* Determine whether the string value of RESPONSE matches the affirmation
837 or negative response expression as specified by the LC_MESSAGES category
838 in the program's current locale. Returns 1 if affirmative, 0 if
839 negative, and -1 if not matching. */
840 extern int rpmatch (const char *__response) __THROW __nonnull ((1)) __wur;
841 #endif
844 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
845 /* Parse comma separated suboption from *OPTIONP and match against
846 strings in TOKENS. If found return index and set *VALUEP to
847 optional value introduced by an equal sign. If the suboption is
848 not part of TOKENS return in *VALUEP beginning of unknown
849 suboption. On exit *OPTIONP is set to the beginning of the next
850 token or at the terminating NUL character. */
851 extern int getsubopt (char **__restrict __optionp,
852 char *const *__restrict __tokens,
853 char **__restrict __valuep)
854 __THROW __nonnull ((1, 2, 3)) __wur;
855 #endif
858 #ifdef __USE_XOPEN
859 /* Setup DES tables according KEY. */
860 extern void setkey (const char *__key) __THROW __nonnull ((1));
861 #endif
864 /* X/Open pseudo terminal handling. */
866 #ifdef __USE_XOPEN2KXSI
867 /* Return a master pseudo-terminal handle. */
868 extern int posix_openpt (int __oflag) __wur;
869 #endif
871 #ifdef __USE_XOPEN_EXTENDED
872 /* The next four functions all take a master pseudo-tty fd and
873 perform an operation on the associated slave: */
875 /* Chown the slave to the calling user. */
876 extern int grantpt (int __fd) __THROW;
878 /* Release an internal lock so the slave can be opened.
879 Call after grantpt(). */
880 extern int unlockpt (int __fd) __THROW;
882 /* Return the pathname of the pseudo terminal slave associated with
883 the master FD is open on, or NULL on errors.
884 The returned storage is good until the next call to this function. */
885 extern char *ptsname (int __fd) __THROW __wur;
886 #endif
888 #ifdef __USE_GNU
889 /* Store at most BUFLEN characters of the pathname of the slave pseudo
890 terminal associated with the master FD is open on in BUF.
891 Return 0 on success, otherwise an error number. */
892 extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
893 __THROW __nonnull ((2));
895 /* Open a master pseudo terminal and return its file descriptor. */
896 extern int getpt (void);
897 #endif
899 #ifdef __USE_MISC
900 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
901 NELEM elements of LOADAVG. Return the number written (never more than
902 three, but may be less than NELEM), or -1 if an error occurred. */
903 extern int getloadavg (double __loadavg[], int __nelem)
904 __THROW __nonnull ((1));
905 #endif
907 #if defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K
908 /* Return the index into the active-logins file (utmp) for
909 the controlling terminal. */
910 extern int ttyslot (void) __THROW;
911 #endif
913 #include <bits/stdlib-float.h>
915 /* Define some macros helping to catch buffer overflows. */
916 #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
917 # include <bits/stdlib.h>
918 #endif
919 #ifdef __LDBL_COMPAT
920 # include <bits/stdlib-ldbl.h>
921 #endif
923 __END_DECLS
925 #endif /* stdlib.h */