stdlib.h 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  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, see
  13. <http://www.gnu.org/licenses/>. */
  14. /*
  15. * ISO C99 Standard: 7.20 General utilities <stdlib.h>
  16. */
  17. #ifndef _STDLIB_H
  18. #include <features.h>
  19. /* Get size_t, wchar_t and NULL from <stddef.h>. */
  20. #define __need_size_t
  21. #ifndef __need_malloc_and_calloc
  22. # ifdef __UCLIBC_HAS_WCHAR__
  23. # define __need_wchar_t
  24. # endif
  25. # define __need_NULL
  26. #endif
  27. #include <stddef.h>
  28. __BEGIN_DECLS
  29. #ifndef __need_malloc_and_calloc
  30. #define _STDLIB_H 1
  31. #if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H
  32. /* XPG requires a few symbols from <sys/wait.h> being defined. */
  33. # include <bits/waitflags.h>
  34. # include <bits/waitstatus.h>
  35. # ifdef __USE_BSD
  36. /* Lots of hair to allow traditional BSD use of `union wait'
  37. as well as POSIX.1 use of `int' for the status word. */
  38. # if defined __GNUC__ && !defined __cplusplus
  39. # define __WAIT_INT(status) \
  40. (__extension__ (((union { __typeof(status) __in; int __i; }) \
  41. { .__in = (status) }).__i))
  42. # else
  43. # define __WAIT_INT(status) (*(int *) &(status))
  44. # endif
  45. /* This is the type of the argument to `wait'. The funky union
  46. causes redeclarations with either `int *' or `union wait *' to be
  47. allowed without complaint. __WAIT_STATUS_DEFN is the type used in
  48. the actual function definitions. */
  49. # if !defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus
  50. # define __WAIT_STATUS void *
  51. # define __WAIT_STATUS_DEFN void *
  52. # else
  53. /* This works in GCC 2.6.1 and later. */
  54. typedef union
  55. {
  56. union wait *__uptr;
  57. int *__iptr;
  58. } __WAIT_STATUS __attribute__ ((__transparent_union__));
  59. # define __WAIT_STATUS_DEFN int *
  60. # endif
  61. # else /* Don't use BSD. */
  62. # define __WAIT_INT(status) (status)
  63. # define __WAIT_STATUS int *
  64. # define __WAIT_STATUS_DEFN int *
  65. # endif /* Use BSD. */
  66. /* Define the macros <sys/wait.h> also would define this way. */
  67. # define WEXITSTATUS(status) __WEXITSTATUS (__WAIT_INT (status))
  68. # define WTERMSIG(status) __WTERMSIG (__WAIT_INT (status))
  69. # define WSTOPSIG(status) __WSTOPSIG (__WAIT_INT (status))
  70. # define WIFEXITED(status) __WIFEXITED (__WAIT_INT (status))
  71. # define WIFSIGNALED(status) __WIFSIGNALED (__WAIT_INT (status))
  72. # define WIFSTOPPED(status) __WIFSTOPPED (__WAIT_INT (status))
  73. # ifdef __WIFCONTINUED
  74. # define WIFCONTINUED(status) __WIFCONTINUED (__WAIT_INT (status))
  75. # endif
  76. #endif /* X/Open and <sys/wait.h> not included. */
  77. __BEGIN_NAMESPACE_STD
  78. /* Returned by `div'. */
  79. typedef struct
  80. {
  81. int quot; /* Quotient. */
  82. int rem; /* Remainder. */
  83. } div_t;
  84. /* Returned by `ldiv'. */
  85. #ifndef __ldiv_t_defined
  86. typedef struct
  87. {
  88. long int quot; /* Quotient. */
  89. long int rem; /* Remainder. */
  90. } ldiv_t;
  91. # define __ldiv_t_defined 1
  92. #endif
  93. __END_NAMESPACE_STD
  94. #if defined __USE_ISOC99 && !defined __lldiv_t_defined
  95. __BEGIN_NAMESPACE_C99
  96. /* Returned by `lldiv'. */
  97. __extension__ typedef struct
  98. {
  99. long long int quot; /* Quotient. */
  100. long long int rem; /* Remainder. */
  101. } lldiv_t;
  102. # define __lldiv_t_defined 1
  103. __END_NAMESPACE_C99
  104. #endif
  105. /* The largest number rand will return (same as INT_MAX). */
  106. #define RAND_MAX 2147483647
  107. /* We define these the same for all machines.
  108. Changes from this to the outside world should be done in `_exit'. */
  109. #define EXIT_FAILURE 1 /* Failing exit status. */
  110. #define EXIT_SUCCESS 0 /* Successful exit status. */
  111. /* Maximum length of a multibyte character in the current locale. */
  112. #if 0
  113. #define MB_CUR_MAX (__ctype_get_mb_cur_max ())
  114. extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
  115. #else
  116. #ifdef __UCLIBC_HAS_WCHAR__
  117. # define MB_CUR_MAX (_stdlib_mb_cur_max ())
  118. extern size_t _stdlib_mb_cur_max (void) __THROW __wur;
  119. libc_hidden_proto(_stdlib_mb_cur_max)
  120. #else
  121. # define MB_CUR_MAX 1
  122. #endif
  123. #endif
  124. __BEGIN_NAMESPACE_STD
  125. #ifdef __UCLIBC_HAS_FLOATS__
  126. /* Convert a string to a floating-point number. */
  127. extern double atof (const char *__nptr)
  128. __THROW __attribute_pure__ __nonnull ((1)) __wur;
  129. #endif /* __UCLIBC_HAS_FLOATS__ */
  130. /* Convert a string to an integer. */
  131. extern int atoi (const char *__nptr)
  132. __THROW __attribute_pure__ __nonnull ((1)) __wur;
  133. libc_hidden_proto(atoi)
  134. /* Convert a string to a long integer. */
  135. extern long int atol (const char *__nptr)
  136. __THROW __attribute_pure__ __nonnull ((1)) __wur;
  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 quad_t 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 problem is
  208. the implementation of the internationalization handling in the
  209. ISO C++ standard library. To support this another set of
  210. the functions using locale data exist which take an additional
  211. argument.
  212. Attention: even though several *_l interfaces are part of POSIX:2008,
  213. these are not. */
  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. #if 0
  290. int rand_type; /* Type of random number generator. */
  291. int rand_deg; /* Degree of random number generator. */
  292. int rand_sep; /* Distance between front and rear. */
  293. #else
  294. /* random_r.c, TYPE_x, DEG_x, SEP_x - small enough for int8_t */
  295. int8_t rand_type; /* Type of random number generator. */
  296. int8_t rand_deg; /* Degree of random number generator. */
  297. int8_t rand_sep; /* Distance between front and rear. */
  298. #endif
  299. int32_t *end_ptr; /* Pointer behind state table. */
  300. };
  301. extern int random_r (struct random_data *__restrict __buf,
  302. int32_t *__restrict __result) __THROW __nonnull ((1, 2));
  303. libc_hidden_proto(random_r)
  304. extern int srandom_r (unsigned int __seed, struct random_data *__buf)
  305. __THROW __nonnull ((2));
  306. libc_hidden_proto(srandom_r)
  307. extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
  308. size_t __statelen,
  309. struct random_data *__restrict __buf)
  310. __THROW __nonnull ((2, 4));
  311. libc_hidden_proto(initstate_r)
  312. extern int setstate_r (char *__restrict __statebuf,
  313. struct random_data *__restrict __buf)
  314. __THROW __nonnull ((1, 2));
  315. libc_hidden_proto(setstate_r)
  316. # endif /* Use misc. */
  317. #endif /* Use SVID || extended X/Open || BSD. */
  318. __BEGIN_NAMESPACE_STD
  319. /* Return a random integer between 0 and RAND_MAX inclusive. */
  320. extern int rand (void) __THROW;
  321. /* Seed the random number generator with the given number. */
  322. extern void srand (unsigned int __seed) __THROW;
  323. __END_NAMESPACE_STD
  324. #ifdef __USE_POSIX
  325. /* Reentrant interface according to POSIX.1. */
  326. extern int rand_r (unsigned int *__seed) __THROW;
  327. #endif
  328. #if defined __USE_SVID || defined __USE_XOPEN
  329. /* System V style 48-bit random number generator functions. */
  330. #ifdef __UCLIBC_HAS_FLOATS__
  331. /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
  332. extern double drand48 (void) __THROW;
  333. extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1));
  334. #endif /* __UCLIBC_HAS_FLOATS__ */
  335. /* Return non-negative, long integer in [0,2^31). */
  336. extern long int lrand48 (void) __THROW;
  337. extern long int nrand48 (unsigned short int __xsubi[3])
  338. __THROW __nonnull ((1));
  339. /* Return signed, long integers in [-2^31,2^31). */
  340. extern long int mrand48 (void) __THROW;
  341. extern long int jrand48 (unsigned short int __xsubi[3])
  342. __THROW __nonnull ((1));
  343. /* Seed random number generator. */
  344. extern void srand48 (long int __seedval) __THROW;
  345. extern unsigned short int *seed48 (unsigned short int __seed16v[3])
  346. __THROW __nonnull ((1));
  347. extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1));
  348. # ifdef __USE_MISC
  349. /* Data structure for communication with thread safe versions. This
  350. type is to be regarded as opaque. It's only exported because users
  351. have to allocate objects of this type. */
  352. struct drand48_data
  353. {
  354. unsigned short int __x[3]; /* Current state. */
  355. unsigned short int __old_x[3]; /* Old state. */
  356. unsigned short int __c; /* Additive const. in congruential formula. */
  357. unsigned short int __init; /* Flag for initializing. */
  358. unsigned long long int __a; /* Factor in congruential formula. */
  359. };
  360. #ifdef __UCLIBC_HAS_FLOATS__
  361. /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
  362. extern int drand48_r (struct drand48_data *__restrict __buffer,
  363. double *__restrict __result) __THROW __nonnull ((1, 2));
  364. extern int erand48_r (unsigned short int __xsubi[3],
  365. struct drand48_data *__restrict __buffer,
  366. double *__restrict __result) __THROW __nonnull ((1, 2));
  367. libc_hidden_proto(erand48_r)
  368. #endif /* __UCLIBC_HAS_FLOATS__ */
  369. /* Return non-negative, long integer in [0,2^31). */
  370. extern int lrand48_r (struct drand48_data *__restrict __buffer,
  371. long int *__restrict __result)
  372. __THROW __nonnull ((1, 2));
  373. libc_hidden_proto(lrand48_r)
  374. extern int nrand48_r (unsigned short int __xsubi[3],
  375. struct drand48_data *__restrict __buffer,
  376. long int *__restrict __result)
  377. __THROW __nonnull ((1, 2));
  378. libc_hidden_proto(nrand48_r)
  379. /* Return signed, long integers in [-2^31,2^31). */
  380. extern int mrand48_r (struct drand48_data *__restrict __buffer,
  381. long int *__restrict __result)
  382. __THROW __nonnull ((1, 2));
  383. extern int jrand48_r (unsigned short int __xsubi[3],
  384. struct drand48_data *__restrict __buffer,
  385. long int *__restrict __result)
  386. __THROW __nonnull ((1, 2));
  387. libc_hidden_proto(jrand48_r)
  388. /* Seed random number generator. */
  389. extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
  390. __THROW __nonnull ((2));
  391. libc_hidden_proto(srand48_r)
  392. extern int seed48_r (unsigned short int __seed16v[3],
  393. struct drand48_data *__buffer) __THROW __nonnull ((1, 2));
  394. libc_hidden_proto(seed48_r)
  395. extern int lcong48_r (unsigned short int __param[7],
  396. struct drand48_data *__buffer)
  397. __THROW __nonnull ((1, 2));
  398. # endif /* Use misc. */
  399. #endif /* Use SVID or X/Open. */
  400. #endif /* don't just need malloc and calloc */
  401. #ifndef __malloc_and_calloc_defined
  402. # define __malloc_and_calloc_defined
  403. __BEGIN_NAMESPACE_STD
  404. /* Allocate SIZE bytes of memory. */
  405. extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
  406. /* We want the malloc symbol overridable at runtime, do not hide it! */
  407. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
  408. extern void *calloc (size_t __nmemb, size_t __size)
  409. __THROW __attribute_malloc__ __wur;
  410. /* We want the calloc symbol overridable at runtime, do not hide it! */
  411. __END_NAMESPACE_STD
  412. #endif
  413. #ifndef __need_malloc_and_calloc
  414. __BEGIN_NAMESPACE_STD
  415. /* Re-allocate the previously allocated block
  416. in PTR, making the new block SIZE bytes long. */
  417. /* __attribute_malloc__ is not used, because if realloc returns
  418. the same pointer that was passed to it, aliasing needs to be allowed
  419. between objects pointed by the old and new pointers. */
  420. extern void *realloc (void *__ptr, size_t __size)
  421. __THROW __wur;
  422. /* We want the realloc symbol overridable at runtime, do not hide it! */
  423. /* Free a block allocated by `malloc', `realloc' or `calloc'. */
  424. extern void free (void *__ptr) __THROW;
  425. /* We want the free symbol overridable at runtime, do not hide it! */
  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. #ifdef __UCLIBC_SUSV2_LEGACY__
  435. # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  436. /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
  437. extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
  438. # endif
  439. #endif
  440. #if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
  441. /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
  442. extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
  443. __THROW __nonnull ((1)) __wur;
  444. #endif
  445. #ifdef __USE_ISOC11
  446. /* ISO C variant of aligned allocation. */
  447. extern void *aligned_alloc (size_t __alignment, size_t __size)
  448. __THROW __attribute_malloc__ __attribute_alloc_size__ ((2)) __wur;
  449. #endif
  450. __BEGIN_NAMESPACE_STD
  451. /* Abort execution and generate a core-dump. */
  452. extern void abort (void) __THROW __attribute__ ((__noreturn__));
  453. libc_hidden_proto(abort)
  454. /* Register a function to be called when `exit' is called. */
  455. extern int atexit (void (*__func) (void)) __THROW __nonnull ((1));
  456. __END_NAMESPACE_STD
  457. #ifdef __USE_MISC
  458. /* Register a function to be called with the status
  459. given to `exit' and the given argument. */
  460. extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
  461. __THROW __nonnull ((1));
  462. #endif
  463. __BEGIN_NAMESPACE_STD
  464. /* Call all functions registered with `atexit' and `on_exit',
  465. in the reverse of the order in which they were registered,
  466. perform stdio cleanup, and terminate program execution with STATUS. */
  467. extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
  468. libc_hidden_proto(exit)
  469. __END_NAMESPACE_STD
  470. #ifdef __USE_ISOC99
  471. __BEGIN_NAMESPACE_C99
  472. /* Terminate the program with STATUS without calling any of the
  473. functions registered with `atexit' or `on_exit'. */
  474. extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
  475. __END_NAMESPACE_C99
  476. #endif
  477. __BEGIN_NAMESPACE_STD
  478. /* Return the value of envariable NAME, or NULL if it doesn't exist. */
  479. extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;
  480. libc_hidden_proto(getenv)
  481. __END_NAMESPACE_STD
  482. /* This function is similar to the above but returns NULL if the
  483. programs is running with SUID or SGID enabled. */
  484. extern char *secure_getenv (const char *__name)
  485. __THROW __nonnull ((1)) __wur;
  486. #if defined __USE_SVID || defined __USE_XOPEN
  487. /* The SVID says this is in <stdio.h>, but this seems a better place. */
  488. /* Put STRING, which is of the form "NAME=VALUE", in the environment.
  489. If there is no `=', remove NAME from the environment. */
  490. extern int putenv (char *__string) __THROW __nonnull ((1));
  491. #endif
  492. #if defined __USE_BSD || defined __USE_XOPEN2K
  493. /* Set NAME to VALUE in the environment.
  494. If REPLACE is nonzero, overwrite an existing value. */
  495. extern int setenv (const char *__name, const char *__value, int __replace)
  496. __THROW __nonnull ((2));
  497. libc_hidden_proto(setenv)
  498. /* Remove the variable NAME from the environment. */
  499. extern int unsetenv (const char *__name) __THROW;
  500. libc_hidden_proto(unsetenv)
  501. #endif
  502. /* The following is used by uClibc in atexit.c and sysconf.c */
  503. /* We have no limit when __UCLIBC_DYNAMIC_ATEXIT__ is enabled. */
  504. #ifdef __UCLIBC_DYNAMIC_ATEXIT__
  505. # define __UCLIBC_MAX_ATEXIT INT_MAX
  506. #else
  507. # define __UCLIBC_MAX_ATEXIT 20
  508. #endif
  509. #ifdef __USE_MISC
  510. /* The `clearenv' was planned to be added to POSIX.1 but probably
  511. never made it. Nevertheless the POSIX.9 standard (POSIX bindings
  512. for Fortran 77) requires this function. */
  513. extern int clearenv (void) __THROW;
  514. #endif
  515. #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  516. # if defined __UCLIBC_SUSV3_LEGACY__
  517. /* Generate a unique temporary file name from TEMPLATE.
  518. The last six characters of TEMPLATE must be "XXXXXX";
  519. they are replaced with a string that makes the file name unique.
  520. Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */
  521. extern char *mktemp (char *__template) __THROW __nonnull ((1)) __wur;
  522. # endif
  523. /* Generate a unique temporary file name from TEMPLATE.
  524. The last six characters of TEMPLATE must be "XXXXXX";
  525. they are replaced with a string that makes the filename unique.
  526. Returns a file descriptor open on the file for reading and writing,
  527. or -1 if it cannot create a uniquely-named file.
  528. This function is a possible cancellation point and therefore not
  529. marked with __THROW. */
  530. # ifndef __USE_FILE_OFFSET64
  531. extern int mkstemp (char *__template) __nonnull ((1)) __wur;
  532. # else
  533. # ifdef __REDIRECT
  534. extern int __REDIRECT (mkstemp, (char *__template), mkstemp64)
  535. __nonnull ((1)) __wur;
  536. # else
  537. # define mkstemp mkstemp64
  538. # endif
  539. # endif
  540. # ifdef __USE_LARGEFILE64
  541. extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
  542. # endif
  543. #endif
  544. #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  545. # if defined __UCLIBC_SUSV3_LEGACY__
  546. extern char *mktemps (char *__template, int __suffixlen) __THROW __nonnull ((1)) __wur;
  547. # endif
  548. /* The mkstemps() function is like mkstemp(), except that the string in
  549. template contains a suffix of suffixlen characters. Thus, template is
  550. of the form prefixXXXXXXsuffix, and the string XXXXXX is modified as
  551. for mkstemp().
  552. Returns a file descriptor open on the file for reading and writing,
  553. or -1 if it cannot create a uniquely-named file.
  554. This function is a possible cancellation point and therefore not
  555. marked with __THROW. */
  556. # ifndef __USE_FILE_OFFSET64
  557. extern int mkstemps (char *__template, int __suffixlen) __nonnull ((1)) __wur;
  558. # else
  559. # ifdef __REDIRECT
  560. extern int __REDIRECT (mkstemps, (char *__template, int __suffixlen), mkstemps64)
  561. __nonnull ((1)) __wur;
  562. # else
  563. # define mkstemps mkstemps64
  564. # endif
  565. # endif
  566. # ifdef __USE_LARGEFILE64
  567. extern int mkstemps64 (char *__template, int __suffixlen) __nonnull ((1)) __wur;
  568. # endif
  569. #endif
  570. #if defined __USE_BSD || defined __USE_XOPEN2K8
  571. /* Create a unique temporary directory from TEMPLATE.
  572. The last six characters of TEMPLATE must be "XXXXXX";
  573. they are replaced with a string that makes the directory name unique.
  574. Returns TEMPLATE, or a null pointer if it cannot get a unique name.
  575. The directory is created mode 700. */
  576. extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
  577. #endif
  578. #ifdef __USE_GNU
  579. /* Generate a unique temporary file name from TEMPLATE similar to
  580. mkstemp. But allow the caller to pass additional flags which are
  581. used in the open call to create the file..
  582. This function is a possible cancellation point and therefore not
  583. marked with __THROW. */
  584. # ifndef __USE_FILE_OFFSET64
  585. extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur;
  586. # else
  587. # ifdef __REDIRECT
  588. extern int __REDIRECT (mkostemp, (char *__template, int __flags), mkostemp64)
  589. __nonnull ((1)) __wur;
  590. # else
  591. # define mkostemp mkostemp64
  592. # endif
  593. # endif
  594. # ifdef __USE_LARGEFILE64
  595. extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur;
  596. # endif
  597. #endif
  598. #ifdef __USE_GNU
  599. /* Generate a unique temporary file name from TEMPLATE similar to
  600. mkostemp. But allow the caller to pass additional file name suffix.
  601. This function is a possible cancellation point and therefore not
  602. marked with __THROW. */
  603. # ifndef __USE_FILE_OFFSET64
  604. extern int mkostemps (char *__template, int __suffixlen, int __flags) __nonnull ((1)) __wur;
  605. # else
  606. # ifdef __REDIRECT
  607. extern int __REDIRECT (mkostemps, (char *__template, int __suffixlen, int __flags), mkostemps64)
  608. __nonnull ((1)) __wur;
  609. # else
  610. # define mkostemps mkostemps64
  611. # endif
  612. # endif
  613. # ifdef __USE_LARGEFILE64
  614. extern int mkostemps64 (char *__template, int __suffixlen, int __flags) __nonnull ((1)) __wur;
  615. # endif
  616. #endif
  617. __BEGIN_NAMESPACE_STD
  618. /* Execute the given line as a shell command.
  619. This function is a cancellation point and therefore not marked with
  620. __THROW. */
  621. extern int system (const char *__command) __wur;
  622. __END_NAMESPACE_STD
  623. #ifdef __USE_GNU
  624. /* Return a malloc'd string containing the canonical absolute name of the
  625. existing named file. */
  626. extern char *canonicalize_file_name (const char *__name)
  627. __THROW __nonnull ((1)) __wur;
  628. #endif
  629. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  630. /* Return the canonical absolute name of file NAME. If RESOLVED is
  631. null, the result is malloc'd; otherwise, if the canonical name is
  632. PATH_MAX chars or more, returns null with `errno' set to
  633. ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
  634. returns the name in RESOLVED. */
  635. extern char *realpath (const char *__restrict __name,
  636. char *__restrict __resolved) __THROW __wur;
  637. libc_hidden_proto(realpath)
  638. #endif
  639. /* Shorthand for type of comparison functions. */
  640. #ifndef __COMPAR_FN_T
  641. # define __COMPAR_FN_T
  642. typedef int (*__compar_fn_t) (const void *, const void *);
  643. # ifdef __USE_GNU
  644. typedef __compar_fn_t comparison_fn_t;
  645. # endif
  646. #endif
  647. #ifdef __USE_GNU
  648. typedef int (*__compar_d_fn_t) (const void *, const void *, void *);
  649. #endif
  650. __BEGIN_NAMESPACE_STD
  651. /* Do a binary search for KEY in BASE, which consists of NMEMB elements
  652. of SIZE bytes each, using COMPAR to perform the comparisons. */
  653. extern void *bsearch (const void *__key, const void *__base,
  654. size_t __nmemb, size_t __size, __compar_fn_t __compar)
  655. __nonnull ((1, 2, 5)) __wur;
  656. /* Sort NMEMB elements of BASE, of SIZE bytes each,
  657. using COMPAR to perform the comparisons. */
  658. extern void qsort (void *__base, size_t __nmemb, size_t __size,
  659. __compar_fn_t __compar) __nonnull ((1, 4));
  660. libc_hidden_proto(qsort)
  661. #ifdef __USE_GNU
  662. extern void qsort_r (void *__base, size_t __nmemb, size_t __size,
  663. __compar_d_fn_t __compar, void *__arg)
  664. __nonnull ((1, 4));
  665. libc_hidden_proto(qsort_r)
  666. #endif
  667. /* Return the absolute value of X. */
  668. extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
  669. extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur;
  670. __END_NAMESPACE_STD
  671. #ifdef __USE_ISOC99
  672. __extension__ extern long long int llabs (long long int __x)
  673. __THROW __attribute__ ((__const__)) __wur;
  674. #endif
  675. __BEGIN_NAMESPACE_STD
  676. /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
  677. of the value of NUMER over DENOM. */
  678. /* GCC may have built-ins for these someday. */
  679. extern div_t div (int __numer, int __denom)
  680. __THROW __attribute__ ((__const__)) __wur;
  681. extern ldiv_t ldiv (long int __numer, long int __denom)
  682. __THROW __attribute__ ((__const__)) __wur;
  683. __END_NAMESPACE_STD
  684. #ifdef __USE_ISOC99
  685. __BEGIN_NAMESPACE_C99
  686. __extension__ extern lldiv_t lldiv (long long int __numer,
  687. long long int __denom)
  688. __THROW __attribute__ ((__const__)) __wur;
  689. __END_NAMESPACE_C99
  690. #endif
  691. #if ( defined __USE_SVID || defined __USE_XOPEN_EXTENDED ) && defined __UCLIBC_HAS_FLOATS__
  692. /* Convert floating point numbers to strings. The returned values are
  693. valid only until another call to the same function. */
  694. # ifdef __UCLIBC_SUSV3_LEGACY__
  695. #if 0
  696. /* Convert VALUE to a string with NDIGIT digits and return a pointer to
  697. this. Set *DECPT with the position of the decimal character and *SIGN
  698. with the sign of the number. */
  699. extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
  700. int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
  701. /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
  702. with the position of the decimal character and *SIGN with the sign of
  703. the number. */
  704. extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
  705. int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
  706. #endif
  707. /* If possible convert VALUE to a string with NDIGIT significant digits.
  708. Otherwise use exponential representation. The resulting string will
  709. be written to BUF. */
  710. extern char *gcvt (double __value, int __ndigit, char *__buf)
  711. __THROW __nonnull ((3)) __wur;
  712. # endif /* __UCLIBC_SUSV3_LEGACY__ */
  713. # if 0 /*def __USE_MISC*/
  714. /* Long double versions of above functions. */
  715. extern char *qecvt (long double __value, int __ndigit,
  716. int *__restrict __decpt, int *__restrict __sign)
  717. __THROW __nonnull ((3, 4)) __wur;
  718. extern char *qfcvt (long double __value, int __ndigit,
  719. int *__restrict __decpt, int *__restrict __sign)
  720. __THROW __nonnull ((3, 4)) __wur;
  721. extern char *qgcvt (long double __value, int __ndigit, char *__buf)
  722. __THROW __nonnull ((3)) __wur;
  723. /* Reentrant version of the functions above which provide their own
  724. buffers. */
  725. extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
  726. int *__restrict __sign, char *__restrict __buf,
  727. size_t __len) __THROW __nonnull ((3, 4, 5));
  728. extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
  729. int *__restrict __sign, char *__restrict __buf,
  730. size_t __len) __THROW __nonnull ((3, 4, 5));
  731. extern int qecvt_r (long double __value, int __ndigit,
  732. int *__restrict __decpt, int *__restrict __sign,
  733. char *__restrict __buf, size_t __len)
  734. __THROW __nonnull ((3, 4, 5));
  735. extern int qfcvt_r (long double __value, int __ndigit,
  736. int *__restrict __decpt, int *__restrict __sign,
  737. char *__restrict __buf, size_t __len)
  738. __THROW __nonnull ((3, 4, 5));
  739. # endif /* misc */
  740. #endif /* use MISC || use X/Open Unix */
  741. #ifdef __UCLIBC_HAS_WCHAR__
  742. __BEGIN_NAMESPACE_STD
  743. /* Return the length of the multibyte character
  744. in S, which is no longer than N. */
  745. extern int mblen (const char *__s, size_t __n) __THROW __wur;
  746. /* Return the length of the given multibyte character,
  747. putting its `wchar_t' representation in *PWC. */
  748. extern int mbtowc (wchar_t *__restrict __pwc,
  749. const char *__restrict __s, size_t __n) __THROW __wur;
  750. /* Put the multibyte character represented
  751. by WCHAR in S, returning its length. */
  752. extern int wctomb (char *__s, wchar_t __wchar) __THROW __wur;
  753. /* Convert a multibyte string to a wide char string. */
  754. extern size_t mbstowcs (wchar_t *__restrict __pwcs,
  755. const char *__restrict __s, size_t __n) __THROW;
  756. /* Convert a wide char string to multibyte string. */
  757. extern size_t wcstombs (char *__restrict __s,
  758. const wchar_t *__restrict __pwcs, size_t __n)
  759. __THROW;
  760. __END_NAMESPACE_STD
  761. #endif /* __UCLIBC_HAS_WCHAR__ */
  762. #ifdef __USE_SVID
  763. /* Determine whether the string value of RESPONSE matches the affirmation
  764. or negative response expression as specified by the LC_MESSAGES category
  765. in the program's current locale. Returns 1 if affirmative, 0 if
  766. negative, and -1 if not matching. */
  767. extern int rpmatch (const char *__response) __THROW __nonnull ((1)) __wur;
  768. #endif
  769. #ifdef __USE_XOPEN_EXTENDED
  770. /* Parse comma separated suboption from *OPTIONP and match against
  771. strings in TOKENS. If found return index and set *VALUEP to
  772. optional value introduced by an equal sign. If the suboption is
  773. not part of TOKENS return in *VALUEP beginning of unknown
  774. suboption. On exit *OPTIONP is set to the beginning of the next
  775. token or at the terminating NUL character. */
  776. extern int getsubopt (char **__restrict __optionp,
  777. char *const *__restrict __tokens,
  778. char **__restrict __valuep)
  779. __THROW __nonnull ((1, 2, 3)) __wur;
  780. #endif
  781. #ifdef __USE_XOPEN
  782. # if defined __UCLIBC_HAS_CRYPT__
  783. /* Setup DES tables according KEY. */
  784. extern void setkey (const char *__key) __THROW __nonnull ((1));
  785. # endif /* __UCLIBC_HAS_CRYPT__ */
  786. #endif
  787. /* X/Open pseudo terminal handling. */
  788. #ifdef __USE_XOPEN2K
  789. /* Return a master pseudo-terminal handle. */
  790. extern int posix_openpt (int __oflag) __wur;
  791. #endif
  792. #ifdef __USE_XOPEN
  793. /* The next four functions all take a master pseudo-tty fd and
  794. perform an operation on the associated slave: */
  795. #ifdef __UCLIBC_HAS_PTY__
  796. /* Chown the slave to the calling user. */
  797. extern int grantpt (int __fd) __THROW;
  798. /* Release an internal lock so the slave can be opened.
  799. Call after grantpt(). */
  800. extern int unlockpt (int __fd) __THROW;
  801. /* Return the pathname of the pseudo terminal slave assoicated with
  802. the master FD is open on, or NULL on errors.
  803. The returned storage is good until the next call to this function. */
  804. extern char *ptsname (int __fd) __THROW __wur;
  805. #endif /* __UCLIBC_HAS_PTY__ */
  806. #endif
  807. #ifdef __USE_GNU
  808. # if defined __UCLIBC_HAS_PTY__
  809. /* Store at most BUFLEN characters of the pathname of the slave pseudo
  810. terminal associated with the master FD is open on in BUF.
  811. Return 0 on success, otherwise an error number. */
  812. extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
  813. __THROW __nonnull ((2));
  814. libc_hidden_proto(ptsname_r)
  815. # endif
  816. # if defined __UCLIBC_HAS_GETPT__
  817. /* Open a master pseudo terminal and return its file descriptor. */
  818. extern int getpt (void);
  819. # endif
  820. #endif
  821. #if 0 /* def __USE_BSD */
  822. /* Put the 1 minute, 5 minute and 15 minute load averages into the first
  823. NELEM elements of LOADAVG. Return the number written (never more than
  824. three, but may be less than NELEM), or -1 if an error occurred. */
  825. extern int getloadavg (double __loadavg[], int __nelem)
  826. __THROW __nonnull ((1));
  827. #endif
  828. #ifdef __UCLIBC_HAS_ARC4RANDOM__
  829. # include <sys/types.h>
  830. extern u_int32_t arc4random(void);
  831. extern void arc4random_stir(void);
  832. extern void arc4random_addrandom(unsigned char *, int);
  833. #endif
  834. #ifdef _LIBC
  835. extern int __drand48_iterate (unsigned short int xsubi[3], struct drand48_data *buffer) attribute_hidden;
  836. /* Global state for non-reentrant functions. */
  837. extern struct drand48_data __libc_drand48_data attribute_hidden;
  838. #endif
  839. #endif /* don't just need malloc and calloc */
  840. #undef __need_malloc_and_calloc
  841. __END_DECLS
  842. #endif /* stdlib.h */