stdlib.h 30 KB

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