stdlib.h 32 KB

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