stdlib.h 34 KB

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