Fix include paths in include/bits/types/*.h.
[glibc.git] / stdlib / stdlib.h
blob428ca2ef6838be5aec7c1629c676077d0d734037
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 /* Returned by `div'. */
55 typedef struct
57 int quot; /* Quotient. */
58 int rem; /* Remainder. */
59 } div_t;
61 /* Returned by `ldiv'. */
62 #ifndef __ldiv_t_defined
63 typedef struct
65 long int quot; /* Quotient. */
66 long int rem; /* Remainder. */
67 } ldiv_t;
68 # define __ldiv_t_defined 1
69 #endif
71 #if defined __USE_ISOC99 && !defined __lldiv_t_defined
72 /* Returned by `lldiv'. */
73 __extension__ typedef struct
75 long long int quot; /* Quotient. */
76 long long int rem; /* Remainder. */
77 } lldiv_t;
78 # define __lldiv_t_defined 1
79 #endif
82 /* The largest number rand will return (same as INT_MAX). */
83 #define RAND_MAX 2147483647
86 /* We define these the same for all machines.
87 Changes from this to the outside world should be done in `_exit'. */
88 #define EXIT_FAILURE 1 /* Failing exit status. */
89 #define EXIT_SUCCESS 0 /* Successful exit status. */
92 /* Maximum length of a multibyte character in the current locale. */
93 #define MB_CUR_MAX (__ctype_get_mb_cur_max ())
94 extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
97 /* Convert a string to a floating-point number. */
98 extern double atof (const char *__nptr)
99 __THROW __attribute_pure__ __nonnull ((1)) __wur;
100 /* Convert a string to an integer. */
101 extern int atoi (const char *__nptr)
102 __THROW __attribute_pure__ __nonnull ((1)) __wur;
103 /* Convert a string to a long integer. */
104 extern long int atol (const char *__nptr)
105 __THROW __attribute_pure__ __nonnull ((1)) __wur;
107 #ifdef __USE_ISOC99
108 /* Convert a string to a long long integer. */
109 __extension__ extern long long int atoll (const char *__nptr)
110 __THROW __attribute_pure__ __nonnull ((1)) __wur;
111 #endif
113 /* Convert a string to a floating-point number. */
114 extern double strtod (const char *__restrict __nptr,
115 char **__restrict __endptr)
116 __THROW __nonnull ((1));
118 #ifdef __USE_ISOC99
119 /* Likewise for `float' and `long double' sizes of floating-point numbers. */
120 extern float strtof (const char *__restrict __nptr,
121 char **__restrict __endptr) __THROW __nonnull ((1));
123 extern long double strtold (const char *__restrict __nptr,
124 char **__restrict __endptr)
125 __THROW __nonnull ((1));
126 #endif
128 /* Convert a string to a long integer. */
129 extern long int strtol (const char *__restrict __nptr,
130 char **__restrict __endptr, int __base)
131 __THROW __nonnull ((1));
132 /* Convert a string to an unsigned long integer. */
133 extern unsigned long int strtoul (const char *__restrict __nptr,
134 char **__restrict __endptr, int __base)
135 __THROW __nonnull ((1));
137 #ifdef __USE_MISC
138 /* Convert a string to a quadword integer. */
139 __extension__
140 extern long long int strtoq (const char *__restrict __nptr,
141 char **__restrict __endptr, int __base)
142 __THROW __nonnull ((1));
143 /* Convert a string to an unsigned quadword integer. */
144 __extension__
145 extern unsigned long long int strtouq (const char *__restrict __nptr,
146 char **__restrict __endptr, int __base)
147 __THROW __nonnull ((1));
148 #endif /* Use misc. */
150 #ifdef __USE_ISOC99
151 /* Convert a string to a quadword integer. */
152 __extension__
153 extern long long int strtoll (const char *__restrict __nptr,
154 char **__restrict __endptr, int __base)
155 __THROW __nonnull ((1));
156 /* Convert a string to an unsigned quadword integer. */
157 __extension__
158 extern unsigned long long int strtoull (const char *__restrict __nptr,
159 char **__restrict __endptr, int __base)
160 __THROW __nonnull ((1));
161 #endif /* ISO C99 or use MISC. */
163 /* Convert a floating-point number to a string. */
164 #if __GLIBC_USE (IEC_60559_BFP_EXT)
165 extern int strfromd (char *__dest, size_t __size, const char *__format,
166 double __f)
167 __THROW __nonnull ((3));
169 extern int strfromf (char *__dest, size_t __size, const char *__format,
170 float __f)
171 __THROW __nonnull ((3));
173 extern int strfroml (char *__dest, size_t __size, const char *__format,
174 long double __f)
175 __THROW __nonnull ((3));
176 #endif
179 #ifdef __USE_GNU
180 /* The concept of one static locale per category is not very well
181 thought out. Many applications will need to process its data using
182 information from several different locales. Another problem is
183 the implementation of the internationalization handling in the
184 ISO C++ standard library. To support this another set of
185 the functions using locale data exist which take an additional
186 argument.
188 Attention: even though several *_l interfaces are part of POSIX:2008,
189 these are not. */
191 /* Structure for reentrant locale using functions. This is an
192 (almost) opaque type for the user level programs. */
193 # include <xlocale.h>
195 /* Special versions of the functions above which take the locale to
196 use as an additional parameter. */
197 extern long int strtol_l (const char *__restrict __nptr,
198 char **__restrict __endptr, int __base,
199 __locale_t __loc) __THROW __nonnull ((1, 4));
201 extern unsigned long int strtoul_l (const char *__restrict __nptr,
202 char **__restrict __endptr,
203 int __base, __locale_t __loc)
204 __THROW __nonnull ((1, 4));
206 __extension__
207 extern long long int strtoll_l (const char *__restrict __nptr,
208 char **__restrict __endptr, int __base,
209 __locale_t __loc)
210 __THROW __nonnull ((1, 4));
212 __extension__
213 extern unsigned long long int strtoull_l (const char *__restrict __nptr,
214 char **__restrict __endptr,
215 int __base, __locale_t __loc)
216 __THROW __nonnull ((1, 4));
218 extern double strtod_l (const char *__restrict __nptr,
219 char **__restrict __endptr, __locale_t __loc)
220 __THROW __nonnull ((1, 3));
222 extern float strtof_l (const char *__restrict __nptr,
223 char **__restrict __endptr, __locale_t __loc)
224 __THROW __nonnull ((1, 3));
226 extern long double strtold_l (const char *__restrict __nptr,
227 char **__restrict __endptr,
228 __locale_t __loc)
229 __THROW __nonnull ((1, 3));
230 #endif /* GNU */
233 #ifdef __USE_EXTERN_INLINES
234 __extern_inline int
235 __NTH (atoi (const char *__nptr))
237 return (int) strtol (__nptr, (char **) NULL, 10);
239 __extern_inline long int
240 __NTH (atol (const char *__nptr))
242 return strtol (__nptr, (char **) NULL, 10);
245 # ifdef __USE_ISOC99
246 __extension__ __extern_inline long long int
247 __NTH (atoll (const char *__nptr))
249 return strtoll (__nptr, (char **) NULL, 10);
251 # endif
252 #endif /* Optimizing and Inlining. */
255 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
256 /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant
257 digit first. Returns a pointer to static storage overwritten by the
258 next call. */
259 extern char *l64a (long int __n) __THROW __wur;
261 /* Read a number from a string S in base 64 as above. */
262 extern long int a64l (const char *__s)
263 __THROW __attribute_pure__ __nonnull ((1)) __wur;
265 #endif /* Use misc || extended X/Open. */
267 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
268 # include <sys/types.h> /* we need int32_t... */
270 /* These are the functions that actually do things. The `random', `srandom',
271 `initstate' and `setstate' functions are those from BSD Unices.
272 The `rand' and `srand' functions are required by the ANSI standard.
273 We provide both interfaces to the same random number generator. */
274 /* Return a random long integer between 0 and RAND_MAX inclusive. */
275 extern long int random (void) __THROW;
277 /* Seed the random number generator with the given number. */
278 extern void srandom (unsigned int __seed) __THROW;
280 /* Initialize the random number generator to use state buffer STATEBUF,
281 of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
282 32, 64, 128 and 256, the bigger the better; values less than 8 will
283 cause an error and values greater than 256 will be rounded down. */
284 extern char *initstate (unsigned int __seed, char *__statebuf,
285 size_t __statelen) __THROW __nonnull ((2));
287 /* Switch the random number generator to state buffer STATEBUF,
288 which should have been previously initialized by `initstate'. */
289 extern char *setstate (char *__statebuf) __THROW __nonnull ((1));
292 # ifdef __USE_MISC
293 /* Reentrant versions of the `random' family of functions.
294 These functions all use the following data structure to contain
295 state, rather than global state variables. */
297 struct random_data
299 int32_t *fptr; /* Front pointer. */
300 int32_t *rptr; /* Rear pointer. */
301 int32_t *state; /* Array of state values. */
302 int rand_type; /* Type of random number generator. */
303 int rand_deg; /* Degree of random number generator. */
304 int rand_sep; /* Distance between front and rear. */
305 int32_t *end_ptr; /* Pointer behind state table. */
308 extern int random_r (struct random_data *__restrict __buf,
309 int32_t *__restrict __result) __THROW __nonnull ((1, 2));
311 extern int srandom_r (unsigned int __seed, struct random_data *__buf)
312 __THROW __nonnull ((2));
314 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
315 size_t __statelen,
316 struct random_data *__restrict __buf)
317 __THROW __nonnull ((2, 4));
319 extern int setstate_r (char *__restrict __statebuf,
320 struct random_data *__restrict __buf)
321 __THROW __nonnull ((1, 2));
322 # endif /* Use misc. */
323 #endif /* Use extended X/Open || misc. */
326 /* Return a random integer between 0 and RAND_MAX inclusive. */
327 extern int rand (void) __THROW;
328 /* Seed the random number generator with the given number. */
329 extern void srand (unsigned int __seed) __THROW;
331 #ifdef __USE_POSIX199506
332 /* Reentrant interface according to POSIX.1. */
333 extern int rand_r (unsigned int *__seed) __THROW;
334 #endif
337 #if defined __USE_MISC || defined __USE_XOPEN
338 /* System V style 48-bit random number generator functions. */
340 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
341 extern double drand48 (void) __THROW;
342 extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1));
344 /* Return non-negative, long integer in [0,2^31). */
345 extern long int lrand48 (void) __THROW;
346 extern long int nrand48 (unsigned short int __xsubi[3])
347 __THROW __nonnull ((1));
349 /* Return signed, long integers in [-2^31,2^31). */
350 extern long int mrand48 (void) __THROW;
351 extern long int jrand48 (unsigned short int __xsubi[3])
352 __THROW __nonnull ((1));
354 /* Seed random number generator. */
355 extern void srand48 (long int __seedval) __THROW;
356 extern unsigned short int *seed48 (unsigned short int __seed16v[3])
357 __THROW __nonnull ((1));
358 extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1));
360 # ifdef __USE_MISC
361 /* Data structure for communication with thread safe versions. This
362 type is to be regarded as opaque. It's only exported because users
363 have to allocate objects of this type. */
364 struct drand48_data
366 unsigned short int __x[3]; /* Current state. */
367 unsigned short int __old_x[3]; /* Old state. */
368 unsigned short int __c; /* Additive const. in congruential formula. */
369 unsigned short int __init; /* Flag for initializing. */
370 __extension__ unsigned long long int __a; /* Factor in congruential
371 formula. */
374 /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
375 extern int drand48_r (struct drand48_data *__restrict __buffer,
376 double *__restrict __result) __THROW __nonnull ((1, 2));
377 extern int erand48_r (unsigned short int __xsubi[3],
378 struct drand48_data *__restrict __buffer,
379 double *__restrict __result) __THROW __nonnull ((1, 2));
381 /* Return non-negative, long integer in [0,2^31). */
382 extern int lrand48_r (struct drand48_data *__restrict __buffer,
383 long int *__restrict __result)
384 __THROW __nonnull ((1, 2));
385 extern int nrand48_r (unsigned short int __xsubi[3],
386 struct drand48_data *__restrict __buffer,
387 long int *__restrict __result)
388 __THROW __nonnull ((1, 2));
390 /* Return signed, long integers in [-2^31,2^31). */
391 extern int mrand48_r (struct drand48_data *__restrict __buffer,
392 long int *__restrict __result)
393 __THROW __nonnull ((1, 2));
394 extern int jrand48_r (unsigned short int __xsubi[3],
395 struct drand48_data *__restrict __buffer,
396 long int *__restrict __result)
397 __THROW __nonnull ((1, 2));
399 /* Seed random number generator. */
400 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
401 __THROW __nonnull ((2));
403 extern int seed48_r (unsigned short int __seed16v[3],
404 struct drand48_data *__buffer) __THROW __nonnull ((1, 2));
406 extern int lcong48_r (unsigned short int __param[7],
407 struct drand48_data *__buffer)
408 __THROW __nonnull ((1, 2));
409 # endif /* Use misc. */
410 #endif /* Use misc or X/Open. */
412 /* Allocate SIZE bytes of memory. */
413 extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
414 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
415 extern void *calloc (size_t __nmemb, size_t __size)
416 __THROW __attribute_malloc__ __wur;
418 /* Re-allocate the previously allocated block
419 in PTR, making the new block SIZE bytes long. */
420 /* __attribute_malloc__ is not used, because if realloc returns
421 the same pointer that was passed to it, aliasing needs to be allowed
422 between objects pointed by the old and new pointers. */
423 extern void *realloc (void *__ptr, size_t __size)
424 __THROW __attribute_warn_unused_result__;
426 #ifdef __USE_GNU
427 /* Re-allocate the previously allocated block in PTR, making the new
428 block large enough for NMEMB elements of SIZE bytes each. */
429 /* __attribute_malloc__ is not used, because if reallocarray returns
430 the same pointer that was passed to it, aliasing needs to be allowed
431 between objects pointed by the old and new pointers. */
432 extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)
433 __THROW __attribute_warn_unused_result__;
434 #endif
436 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
437 extern void free (void *__ptr) __THROW;
439 #ifdef __USE_MISC
440 # include <alloca.h>
441 #endif /* Use misc. */
443 #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \
444 || defined __USE_MISC
445 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
446 extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
447 #endif
449 #ifdef __USE_XOPEN2K
450 /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
451 extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
452 __THROW __nonnull ((1)) __wur;
453 #endif
455 #ifdef __USE_ISOC11
456 /* ISO C variant of aligned allocation. */
457 extern void *aligned_alloc (size_t __alignment, size_t __size)
458 __THROW __attribute_malloc__ __attribute_alloc_size__ ((2)) __wur;
459 #endif
461 /* Abort execution and generate a core-dump. */
462 extern void abort (void) __THROW __attribute__ ((__noreturn__));
465 /* Register a function to be called when `exit' is called. */
466 extern int atexit (void (*__func) (void)) __THROW __nonnull ((1));
468 #if defined __USE_ISOC11 || defined __USE_ISOCXX11
469 /* Register a function to be called when `quick_exit' is called. */
470 # ifdef __cplusplus
471 extern "C++" int at_quick_exit (void (*__func) (void))
472 __THROW __asm ("at_quick_exit") __nonnull ((1));
473 # else
474 extern int at_quick_exit (void (*__func) (void)) __THROW __nonnull ((1));
475 # endif
476 #endif
478 #ifdef __USE_MISC
479 /* Register a function to be called with the status
480 given to `exit' and the given argument. */
481 extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
482 __THROW __nonnull ((1));
483 #endif
485 /* Call all functions registered with `atexit' and `on_exit',
486 in the reverse of the order in which they were registered,
487 perform stdio cleanup, and terminate program execution with STATUS. */
488 extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
490 #if defined __USE_ISOC11 || defined __USE_ISOCXX11
491 /* Call all functions registered with `at_quick_exit' in the reverse
492 of the order in which they were registered and terminate program
493 execution with STATUS. */
494 extern void quick_exit (int __status) __THROW __attribute__ ((__noreturn__));
495 #endif
497 #ifdef __USE_ISOC99
498 /* Terminate the program with STATUS without calling any of the
499 functions registered with `atexit' or `on_exit'. */
500 extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
501 #endif
504 /* Return the value of envariable NAME, or NULL if it doesn't exist. */
505 extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;
507 #ifdef __USE_GNU
508 /* This function is similar to the above but returns NULL if the
509 programs is running with SUID or SGID enabled. */
510 extern char *secure_getenv (const char *__name)
511 __THROW __nonnull ((1)) __wur;
512 #endif
514 #if defined __USE_MISC || defined __USE_XOPEN
515 /* The SVID says this is in <stdio.h>, but this seems a better place. */
516 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
517 If there is no `=', remove NAME from the environment. */
518 extern int putenv (char *__string) __THROW __nonnull ((1));
519 #endif
521 #ifdef __USE_XOPEN2K
522 /* Set NAME to VALUE in the environment.
523 If REPLACE is nonzero, overwrite an existing value. */
524 extern int setenv (const char *__name, const char *__value, int __replace)
525 __THROW __nonnull ((2));
527 /* Remove the variable NAME from the environment. */
528 extern int unsetenv (const char *__name) __THROW __nonnull ((1));
529 #endif
531 #ifdef __USE_MISC
532 /* The `clearenv' was planned to be added to POSIX.1 but probably
533 never made it. Nevertheless the POSIX.9 standard (POSIX bindings
534 for Fortran 77) requires this function. */
535 extern int clearenv (void) __THROW;
536 #endif
539 #if defined __USE_MISC \
540 || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8)
541 /* Generate a unique temporary file name from TEMPLATE.
542 The last six characters of TEMPLATE must be "XXXXXX";
543 they are replaced with a string that makes the file name unique.
544 Always returns TEMPLATE, it's either a temporary file name or a null
545 string if it cannot get a unique file name. */
546 extern char *mktemp (char *__template) __THROW __nonnull ((1));
547 #endif
549 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
550 /* Generate a unique temporary file name from TEMPLATE.
551 The last six characters of TEMPLATE must be "XXXXXX";
552 they are replaced with a string that makes the filename unique.
553 Returns a file descriptor open on the file for reading and writing,
554 or -1 if it cannot create a uniquely-named file.
556 This function is a possible cancellation point and therefore not
557 marked with __THROW. */
558 # ifndef __USE_FILE_OFFSET64
559 extern int mkstemp (char *__template) __nonnull ((1)) __wur;
560 # else
561 # ifdef __REDIRECT
562 extern int __REDIRECT (mkstemp, (char *__template), mkstemp64)
563 __nonnull ((1)) __wur;
564 # else
565 # define mkstemp mkstemp64
566 # endif
567 # endif
568 # ifdef __USE_LARGEFILE64
569 extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
570 # endif
571 #endif
573 #ifdef __USE_MISC
574 /* Similar to mkstemp, but the template can have a suffix after the
575 XXXXXX. The length of the suffix is specified in the second
576 parameter.
578 This function is a possible cancellation point and therefore not
579 marked with __THROW. */
580 # ifndef __USE_FILE_OFFSET64
581 extern int mkstemps (char *__template, int __suffixlen) __nonnull ((1)) __wur;
582 # else
583 # ifdef __REDIRECT
584 extern int __REDIRECT (mkstemps, (char *__template, int __suffixlen),
585 mkstemps64) __nonnull ((1)) __wur;
586 # else
587 # define mkstemps mkstemps64
588 # endif
589 # endif
590 # ifdef __USE_LARGEFILE64
591 extern int mkstemps64 (char *__template, int __suffixlen)
592 __nonnull ((1)) __wur;
593 # endif
594 #endif
596 #ifdef __USE_XOPEN2K8
597 /* Create a unique temporary directory from TEMPLATE.
598 The last six characters of TEMPLATE must be "XXXXXX";
599 they are replaced with a string that makes the directory name unique.
600 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
601 The directory is created mode 700. */
602 extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
603 #endif
605 #ifdef __USE_GNU
606 /* Generate a unique temporary file name from TEMPLATE similar to
607 mkstemp. But allow the caller to pass additional flags which are
608 used in the open call to create the file..
610 This function is a possible cancellation point and therefore not
611 marked with __THROW. */
612 # ifndef __USE_FILE_OFFSET64
613 extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur;
614 # else
615 # ifdef __REDIRECT
616 extern int __REDIRECT (mkostemp, (char *__template, int __flags), mkostemp64)
617 __nonnull ((1)) __wur;
618 # else
619 # define mkostemp mkostemp64
620 # endif
621 # endif
622 # ifdef __USE_LARGEFILE64
623 extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur;
624 # endif
626 /* Similar to mkostemp, but the template can have a suffix after the
627 XXXXXX. The length of the suffix is specified in the second
628 parameter.
630 This function is a possible cancellation point and therefore not
631 marked with __THROW. */
632 # ifndef __USE_FILE_OFFSET64
633 extern int mkostemps (char *__template, int __suffixlen, int __flags)
634 __nonnull ((1)) __wur;
635 # else
636 # ifdef __REDIRECT
637 extern int __REDIRECT (mkostemps, (char *__template, int __suffixlen,
638 int __flags), mkostemps64)
639 __nonnull ((1)) __wur;
640 # else
641 # define mkostemps mkostemps64
642 # endif
643 # endif
644 # ifdef __USE_LARGEFILE64
645 extern int mkostemps64 (char *__template, int __suffixlen, int __flags)
646 __nonnull ((1)) __wur;
647 # endif
648 #endif
651 /* Execute the given line as a shell command.
653 This function is a cancellation point and therefore not marked with
654 __THROW. */
655 extern int system (const char *__command) __wur;
658 #ifdef __USE_GNU
659 /* Return a malloc'd string containing the canonical absolute name of the
660 existing named file. */
661 extern char *canonicalize_file_name (const char *__name)
662 __THROW __nonnull ((1)) __wur;
663 #endif
665 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
666 /* Return the canonical absolute name of file NAME. If RESOLVED is
667 null, the result is malloc'd; otherwise, if the canonical name is
668 PATH_MAX chars or more, returns null with `errno' set to
669 ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
670 returns the name in RESOLVED. */
671 extern char *realpath (const char *__restrict __name,
672 char *__restrict __resolved) __THROW __wur;
673 #endif
676 /* Shorthand for type of comparison functions. */
677 #ifndef __COMPAR_FN_T
678 # define __COMPAR_FN_T
679 typedef int (*__compar_fn_t) (const void *, const void *);
681 # ifdef __USE_GNU
682 typedef __compar_fn_t comparison_fn_t;
683 # endif
684 #endif
685 #ifdef __USE_GNU
686 typedef int (*__compar_d_fn_t) (const void *, const void *, void *);
687 #endif
689 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
690 of SIZE bytes each, using COMPAR to perform the comparisons. */
691 extern void *bsearch (const void *__key, const void *__base,
692 size_t __nmemb, size_t __size, __compar_fn_t __compar)
693 __nonnull ((1, 2, 5)) __wur;
695 #ifdef __USE_EXTERN_INLINES
696 # include <bits/stdlib-bsearch.h>
697 #endif
699 /* Sort NMEMB elements of BASE, of SIZE bytes each,
700 using COMPAR to perform the comparisons. */
701 extern void qsort (void *__base, size_t __nmemb, size_t __size,
702 __compar_fn_t __compar) __nonnull ((1, 4));
703 #ifdef __USE_GNU
704 extern void qsort_r (void *__base, size_t __nmemb, size_t __size,
705 __compar_d_fn_t __compar, void *__arg)
706 __nonnull ((1, 4));
707 #endif
710 /* Return the absolute value of X. */
711 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
712 extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur;
714 #ifdef __USE_ISOC99
715 __extension__ extern long long int llabs (long long int __x)
716 __THROW __attribute__ ((__const__)) __wur;
717 #endif
720 /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
721 of the value of NUMER over DENOM. */
722 /* GCC may have built-ins for these someday. */
723 extern div_t div (int __numer, int __denom)
724 __THROW __attribute__ ((__const__)) __wur;
725 extern ldiv_t ldiv (long int __numer, long int __denom)
726 __THROW __attribute__ ((__const__)) __wur;
728 #ifdef __USE_ISOC99
729 __extension__ extern lldiv_t lldiv (long long int __numer,
730 long long int __denom)
731 __THROW __attribute__ ((__const__)) __wur;
732 #endif
735 #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \
736 || defined __USE_MISC
737 /* Convert floating point numbers to strings. The returned values are
738 valid only until another call to the same function. */
740 /* Convert VALUE to a string with NDIGIT digits and return a pointer to
741 this. Set *DECPT with the position of the decimal character and *SIGN
742 with the sign of the number. */
743 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
744 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
746 /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
747 with the position of the decimal character and *SIGN with the sign of
748 the number. */
749 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
750 int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
752 /* If possible convert VALUE to a string with NDIGIT significant digits.
753 Otherwise use exponential representation. The resulting string will
754 be written to BUF. */
755 extern char *gcvt (double __value, int __ndigit, char *__buf)
756 __THROW __nonnull ((3)) __wur;
757 #endif
759 #ifdef __USE_MISC
760 /* Long double versions of above functions. */
761 extern char *qecvt (long double __value, int __ndigit,
762 int *__restrict __decpt, int *__restrict __sign)
763 __THROW __nonnull ((3, 4)) __wur;
764 extern char *qfcvt (long double __value, int __ndigit,
765 int *__restrict __decpt, int *__restrict __sign)
766 __THROW __nonnull ((3, 4)) __wur;
767 extern char *qgcvt (long double __value, int __ndigit, char *__buf)
768 __THROW __nonnull ((3)) __wur;
771 /* Reentrant version of the functions above which provide their own
772 buffers. */
773 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
774 int *__restrict __sign, char *__restrict __buf,
775 size_t __len) __THROW __nonnull ((3, 4, 5));
776 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
777 int *__restrict __sign, char *__restrict __buf,
778 size_t __len) __THROW __nonnull ((3, 4, 5));
780 extern int qecvt_r (long double __value, int __ndigit,
781 int *__restrict __decpt, int *__restrict __sign,
782 char *__restrict __buf, size_t __len)
783 __THROW __nonnull ((3, 4, 5));
784 extern int qfcvt_r (long double __value, int __ndigit,
785 int *__restrict __decpt, int *__restrict __sign,
786 char *__restrict __buf, size_t __len)
787 __THROW __nonnull ((3, 4, 5));
788 #endif /* misc */
791 /* Return the length of the multibyte character
792 in S, which is no longer than N. */
793 extern int mblen (const char *__s, size_t __n) __THROW;
794 /* Return the length of the given multibyte character,
795 putting its `wchar_t' representation in *PWC. */
796 extern int mbtowc (wchar_t *__restrict __pwc,
797 const char *__restrict __s, size_t __n) __THROW;
798 /* Put the multibyte character represented
799 by WCHAR in S, returning its length. */
800 extern int wctomb (char *__s, wchar_t __wchar) __THROW;
803 /* Convert a multibyte string to a wide char string. */
804 extern size_t mbstowcs (wchar_t *__restrict __pwcs,
805 const char *__restrict __s, size_t __n) __THROW;
806 /* Convert a wide char string to multibyte string. */
807 extern size_t wcstombs (char *__restrict __s,
808 const wchar_t *__restrict __pwcs, size_t __n)
809 __THROW;
812 #ifdef __USE_MISC
813 /* Determine whether the string value of RESPONSE matches the affirmation
814 or negative response expression as specified by the LC_MESSAGES category
815 in the program's current locale. Returns 1 if affirmative, 0 if
816 negative, and -1 if not matching. */
817 extern int rpmatch (const char *__response) __THROW __nonnull ((1)) __wur;
818 #endif
821 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
822 /* Parse comma separated suboption from *OPTIONP and match against
823 strings in TOKENS. If found return index and set *VALUEP to
824 optional value introduced by an equal sign. If the suboption is
825 not part of TOKENS return in *VALUEP beginning of unknown
826 suboption. On exit *OPTIONP is set to the beginning of the next
827 token or at the terminating NUL character. */
828 extern int getsubopt (char **__restrict __optionp,
829 char *const *__restrict __tokens,
830 char **__restrict __valuep)
831 __THROW __nonnull ((1, 2, 3)) __wur;
832 #endif
835 #ifdef __USE_XOPEN
836 /* Setup DES tables according KEY. */
837 extern void setkey (const char *__key) __THROW __nonnull ((1));
838 #endif
841 /* X/Open pseudo terminal handling. */
843 #ifdef __USE_XOPEN2KXSI
844 /* Return a master pseudo-terminal handle. */
845 extern int posix_openpt (int __oflag) __wur;
846 #endif
848 #ifdef __USE_XOPEN_EXTENDED
849 /* The next four functions all take a master pseudo-tty fd and
850 perform an operation on the associated slave: */
852 /* Chown the slave to the calling user. */
853 extern int grantpt (int __fd) __THROW;
855 /* Release an internal lock so the slave can be opened.
856 Call after grantpt(). */
857 extern int unlockpt (int __fd) __THROW;
859 /* Return the pathname of the pseudo terminal slave associated with
860 the master FD is open on, or NULL on errors.
861 The returned storage is good until the next call to this function. */
862 extern char *ptsname (int __fd) __THROW __wur;
863 #endif
865 #ifdef __USE_GNU
866 /* Store at most BUFLEN characters of the pathname of the slave pseudo
867 terminal associated with the master FD is open on in BUF.
868 Return 0 on success, otherwise an error number. */
869 extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
870 __THROW __nonnull ((2));
872 /* Open a master pseudo terminal and return its file descriptor. */
873 extern int getpt (void);
874 #endif
876 #ifdef __USE_MISC
877 /* Put the 1 minute, 5 minute and 15 minute load averages into the first
878 NELEM elements of LOADAVG. Return the number written (never more than
879 three, but may be less than NELEM), or -1 if an error occurred. */
880 extern int getloadavg (double __loadavg[], int __nelem)
881 __THROW __nonnull ((1));
882 #endif
884 #if defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K
885 /* Return the index into the active-logins file (utmp) for
886 the controlling terminal. */
887 extern int ttyslot (void) __THROW;
888 #endif
890 #include <bits/stdlib-float.h>
892 /* Define some macros helping to catch buffer overflows. */
893 #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
894 # include <bits/stdlib.h>
895 #endif
896 #ifdef __LDBL_COMPAT
897 # include <bits/stdlib-ldbl.h>
898 #endif
900 __END_DECLS
902 #endif /* stdlib.h */