stdlib.h 33 KB

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