stdlib.h 33 KB

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