stdlib.h 32 KB

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