stdlib.h 33 KB

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