stdlib.h 32 KB

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