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