stdlib.h 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. /* Copyright (C) 1991-2020 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. /*
  15. * ISO C99 Standard: 7.20 General utilities <stdlib.h>
  16. */
  17. #ifndef _STDLIB_H
  18. #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
  19. #include <bits/libc-header-start.h>
  20. /* Get size_t, wchar_t and NULL from <stddef.h>. */
  21. #define __need_size_t
  22. #define __need_wchar_t
  23. #define __need_NULL
  24. #include <stddef.h>
  25. __BEGIN_DECLS
  26. #define _STDLIB_H 1
  27. #if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H
  28. /* XPG requires a few symbols from <sys/wait.h> being defined. */
  29. # include <bits/waitflags.h>
  30. # include <bits/waitstatus.h>
  31. /* Define the macros <sys/wait.h> also would define this way. */
  32. # define WEXITSTATUS(status) __WEXITSTATUS (status)
  33. # define WTERMSIG(status) __WTERMSIG (status)
  34. # define WSTOPSIG(status) __WSTOPSIG (status)
  35. # define WIFEXITED(status) __WIFEXITED (status)
  36. # define WIFSIGNALED(status) __WIFSIGNALED (status)
  37. # define WIFSTOPPED(status) __WIFSTOPPED (status)
  38. # ifdef __WIFCONTINUED
  39. # define WIFCONTINUED(status) __WIFCONTINUED (status)
  40. # endif
  41. #endif /* X/Open or XPG7 and <sys/wait.h> not included. */
  42. /* _FloatN API tests for enablement. */
  43. #include <bits/floatn.h>
  44. /* Returned by `div'. */
  45. typedef struct
  46. {
  47. int quot; /* Quotient. */
  48. int rem; /* Remainder. */
  49. } div_t;
  50. /* Returned by `ldiv'. */
  51. #ifndef __ldiv_t_defined
  52. typedef struct
  53. {
  54. long int quot; /* Quotient. */
  55. long int rem; /* Remainder. */
  56. } ldiv_t;
  57. # define __ldiv_t_defined 1
  58. #endif
  59. #if defined __USE_ISOC99 && !defined __lldiv_t_defined
  60. /* Returned by `lldiv'. */
  61. __extension__ typedef struct
  62. {
  63. long long int quot; /* Quotient. */
  64. long long int rem; /* Remainder. */
  65. } lldiv_t;
  66. # define __lldiv_t_defined 1
  67. #endif
  68. /* The largest number rand will return (same as INT_MAX). */
  69. #define RAND_MAX 2147483647
  70. /* We define these the same for all machines.
  71. Changes from this to the outside world should be done in `_exit'. */
  72. #define EXIT_FAILURE 1 /* Failing exit status. */
  73. #define EXIT_SUCCESS 0 /* Successful exit status. */
  74. /* Maximum length of a multibyte character in the current locale. */
  75. #define MB_CUR_MAX (__ctype_get_mb_cur_max ())
  76. extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
  77. /* Convert a string to a floating-point number. */
  78. extern double atof (const char *__nptr)
  79. __THROW __attribute_pure__ __nonnull ((1)) __wur;
  80. /* Convert a string to an integer. */
  81. extern int atoi (const char *__nptr)
  82. __THROW __attribute_pure__ __nonnull ((1)) __wur;
  83. /* Convert a string to a long integer. */
  84. extern long int atol (const char *__nptr)
  85. __THROW __attribute_pure__ __nonnull ((1)) __wur;
  86. #ifdef __USE_ISOC99
  87. /* Convert a string to a long long integer. */
  88. __extension__ extern long long int atoll (const char *__nptr)
  89. __THROW __attribute_pure__ __nonnull ((1)) __wur;
  90. #endif
  91. /* Convert a string to a floating-point number. */
  92. extern double strtod (const char *__restrict __nptr,
  93. char **__restrict __endptr)
  94. __THROW __nonnull ((1));
  95. #ifdef __USE_ISOC99
  96. /* Likewise for `float' and `long double' sizes of floating-point numbers. */
  97. extern float strtof (const char *__restrict __nptr,
  98. char **__restrict __endptr) __THROW __nonnull ((1));
  99. extern long double strtold (const char *__restrict __nptr,
  100. char **__restrict __endptr)
  101. __THROW __nonnull ((1));
  102. #endif
  103. /* Likewise for '_FloatN' and '_FloatNx'. */
  104. #if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  105. extern _Float16 strtof16 (const char *__restrict __nptr,
  106. char **__restrict __endptr)
  107. __THROW __nonnull ((1));
  108. #endif
  109. #if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  110. extern _Float32 strtof32 (const char *__restrict __nptr,
  111. char **__restrict __endptr)
  112. __THROW __nonnull ((1));
  113. #endif
  114. #if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  115. extern _Float64 strtof64 (const char *__restrict __nptr,
  116. char **__restrict __endptr)
  117. __THROW __nonnull ((1));
  118. #endif
  119. #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  120. extern _Float128 strtof128 (const char *__restrict __nptr,
  121. char **__restrict __endptr)
  122. __THROW __nonnull ((1));
  123. #endif
  124. #if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
  125. extern _Float32x strtof32x (const char *__restrict __nptr,
  126. char **__restrict __endptr)
  127. __THROW __nonnull ((1));
  128. #endif
  129. #if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
  130. extern _Float64x strtof64x (const char *__restrict __nptr,
  131. char **__restrict __endptr)
  132. __THROW __nonnull ((1));
  133. #endif
  134. #if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
  135. extern _Float128x strtof128x (const char *__restrict __nptr,
  136. char **__restrict __endptr)
  137. __THROW __nonnull ((1));
  138. #endif
  139. /* Convert a string to a long integer. */
  140. extern long int strtol (const char *__restrict __nptr,
  141. char **__restrict __endptr, int __base)
  142. __THROW __nonnull ((1));
  143. /* Convert a string to an unsigned long integer. */
  144. extern unsigned long int strtoul (const char *__restrict __nptr,
  145. char **__restrict __endptr, int __base)
  146. __THROW __nonnull ((1));
  147. #ifdef __USE_MISC
  148. /* Convert a string to a quadword integer. */
  149. __extension__
  150. extern long long int strtoq (const char *__restrict __nptr,
  151. char **__restrict __endptr, int __base)
  152. __THROW __nonnull ((1));
  153. /* Convert a string to an unsigned quadword integer. */
  154. __extension__
  155. extern unsigned long long int strtouq (const char *__restrict __nptr,
  156. char **__restrict __endptr, int __base)
  157. __THROW __nonnull ((1));
  158. #endif /* Use misc. */
  159. #ifdef __USE_ISOC99
  160. /* Convert a string to a quadword integer. */
  161. __extension__
  162. extern long long int strtoll (const char *__restrict __nptr,
  163. char **__restrict __endptr, int __base)
  164. __THROW __nonnull ((1));
  165. /* Convert a string to an unsigned quadword integer. */
  166. __extension__
  167. extern unsigned long long int strtoull (const char *__restrict __nptr,
  168. char **__restrict __endptr, int __base)
  169. __THROW __nonnull ((1));
  170. #endif /* ISO C99 or use MISC. */
  171. /* Convert a floating-point number to a string. */
  172. #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
  173. extern int strfromd (char *__dest, size_t __size, const char *__format,
  174. double __f)
  175. __THROW __nonnull ((3));
  176. extern int strfromf (char *__dest, size_t __size, const char *__format,
  177. float __f)
  178. __THROW __nonnull ((3));
  179. extern int strfroml (char *__dest, size_t __size, const char *__format,
  180. long double __f)
  181. __THROW __nonnull ((3));
  182. #endif
  183. #if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  184. extern int strfromf16 (char *__dest, size_t __size, const char * __format,
  185. _Float16 __f)
  186. __THROW __nonnull ((3));
  187. #endif
  188. #if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  189. extern int strfromf32 (char *__dest, size_t __size, const char * __format,
  190. _Float32 __f)
  191. __THROW __nonnull ((3));
  192. #endif
  193. #if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  194. extern int strfromf64 (char *__dest, size_t __size, const char * __format,
  195. _Float64 __f)
  196. __THROW __nonnull ((3));
  197. #endif
  198. #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
  199. extern int strfromf128 (char *__dest, size_t __size, const char * __format,
  200. _Float128 __f)
  201. __THROW __nonnull ((3));
  202. #endif
  203. #if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
  204. extern int strfromf32x (char *__dest, size_t __size, const char * __format,
  205. _Float32x __f)
  206. __THROW __nonnull ((3));
  207. #endif
  208. #if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
  209. extern int strfromf64x (char *__dest, size_t __size, const char * __format,
  210. _Float64x __f)
  211. __THROW __nonnull ((3));
  212. #endif
  213. #if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
  214. extern int strfromf128x (char *__dest, size_t __size, const char * __format,
  215. _Float128x __f)
  216. __THROW __nonnull ((3));
  217. #endif
  218. #ifdef __USE_GNU
  219. /* Parallel versions of the functions above which take the locale to
  220. use as an additional parameter. These are GNU extensions inspired
  221. by the POSIX.1-2008 extended locale API. */
  222. # include <bits/types/locale_t.h>
  223. extern long int strtol_l (const char *__restrict __nptr,
  224. char **__restrict __endptr, int __base,
  225. locale_t __loc) __THROW __nonnull ((1, 4));
  226. extern unsigned long int strtoul_l (const char *__restrict __nptr,
  227. char **__restrict __endptr,
  228. int __base, locale_t __loc)
  229. __THROW __nonnull ((1, 4));
  230. __extension__
  231. extern long long int strtoll_l (const char *__restrict __nptr,
  232. char **__restrict __endptr, int __base,
  233. locale_t __loc)
  234. __THROW __nonnull ((1, 4));
  235. __extension__
  236. extern unsigned long long int strtoull_l (const char *__restrict __nptr,
  237. char **__restrict __endptr,
  238. int __base, locale_t __loc)
  239. __THROW __nonnull ((1, 4));
  240. extern double strtod_l (const char *__restrict __nptr,
  241. char **__restrict __endptr, locale_t __loc)
  242. __THROW __nonnull ((1, 3));
  243. extern float strtof_l (const char *__restrict __nptr,
  244. char **__restrict __endptr, locale_t __loc)
  245. __THROW __nonnull ((1, 3));
  246. extern long double strtold_l (const char *__restrict __nptr,
  247. char **__restrict __endptr,
  248. locale_t __loc)
  249. __THROW __nonnull ((1, 3));
  250. # if __HAVE_FLOAT16
  251. extern _Float16 strtof16_l (const char *__restrict __nptr,
  252. char **__restrict __endptr,
  253. locale_t __loc)
  254. __THROW __nonnull ((1, 3));
  255. # endif
  256. # if __HAVE_FLOAT32
  257. extern _Float32 strtof32_l (const char *__restrict __nptr,
  258. char **__restrict __endptr,
  259. locale_t __loc)
  260. __THROW __nonnull ((1, 3));
  261. # endif
  262. # if __HAVE_FLOAT64
  263. extern _Float64 strtof64_l (const char *__restrict __nptr,
  264. char **__restrict __endptr,
  265. locale_t __loc)
  266. __THROW __nonnull ((1, 3));
  267. # endif
  268. # if __HAVE_FLOAT128
  269. extern _Float128 strtof128_l (const char *__restrict __nptr,
  270. char **__restrict __endptr,
  271. locale_t __loc)
  272. __THROW __nonnull ((1, 3));
  273. # endif
  274. # if __HAVE_FLOAT32X
  275. extern _Float32x strtof32x_l (const char *__restrict __nptr,
  276. char **__restrict __endptr,
  277. locale_t __loc)
  278. __THROW __nonnull ((1, 3));
  279. # endif
  280. # if __HAVE_FLOAT64X
  281. extern _Float64x strtof64x_l (const char *__restrict __nptr,
  282. char **__restrict __endptr,
  283. locale_t __loc)
  284. __THROW __nonnull ((1, 3));
  285. # endif
  286. # if __HAVE_FLOAT128X
  287. extern _Float128x strtof128x_l (const char *__restrict __nptr,
  288. char **__restrict __endptr,
  289. locale_t __loc)
  290. __THROW __nonnull ((1, 3));
  291. # endif
  292. #endif /* GNU */
  293. #ifdef __USE_EXTERN_INLINES
  294. __extern_inline int
  295. __NTH (atoi (const char *__nptr))
  296. {
  297. return (int) strtol (__nptr, (char **) NULL, 10);
  298. }
  299. __extern_inline long int
  300. __NTH (atol (const char *__nptr))
  301. {
  302. return strtol (__nptr, (char **) NULL, 10);
  303. }
  304. # ifdef __USE_ISOC99
  305. __extension__ __extern_inline long long int
  306. __NTH (atoll (const char *__nptr))
  307. {
  308. return strtoll (__nptr, (char **) NULL, 10);
  309. }
  310. # endif
  311. #endif /* Optimizing and Inlining. */
  312. #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  313. /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant
  314. digit first. Returns a pointer to static storage overwritten by the
  315. next call. */
  316. extern char *l64a (long int __n) __THROW __wur;
  317. /* Read a number from a string S in base 64 as above. */
  318. extern long int a64l (const char *__s)
  319. __THROW __attribute_pure__ __nonnull ((1)) __wur;
  320. #endif /* Use misc || extended X/Open. */
  321. #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  322. # include <sys/types.h> /* we need int32_t... */
  323. /* These are the functions that actually do things. The `random', `srandom',
  324. `initstate' and `setstate' functions are those from BSD Unices.
  325. The `rand' and `srand' functions are required by the ANSI standard.
  326. We provide both interfaces to the same random number generator. */
  327. /* Return a random long integer between 0 and RAND_MAX inclusive. */
  328. extern long int random (void) __THROW;
  329. /* Seed the random number generator with the given number. */
  330. extern void srandom (unsigned int __seed) __THROW;
  331. /* Initialize the random number generator to use state buffer STATEBUF,
  332. of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
  333. 32, 64, 128 and 256, the bigger the better; values less than 8 will
  334. cause an error and values greater than 256 will be rounded down. */
  335. extern char *initstate (unsigned int __seed, char *__statebuf,
  336. size_t __statelen) __THROW __nonnull ((2));
  337. /* Switch the random number generator to state buffer STATEBUF,
  338. which should have been previously initialized by `initstate'. */
  339. extern char *setstate (char *__statebuf) __THROW __nonnull ((1));
  340. # ifdef __USE_MISC
  341. /* Reentrant versions of the `random' family of functions.
  342. These functions all use the following data structure to contain
  343. state, rather than global state variables. */
  344. struct random_data
  345. {
  346. int32_t *fptr; /* Front pointer. */
  347. int32_t *rptr; /* Rear pointer. */
  348. int32_t *state; /* Array of state values. */
  349. int rand_type; /* Type of random number generator. */
  350. int rand_deg; /* Degree of random number generator. */
  351. int rand_sep; /* Distance between front and rear. */
  352. int32_t *end_ptr; /* Pointer behind state table. */
  353. };
  354. extern int random_r (struct random_data *__restrict __buf,
  355. int32_t *__restrict __result) __THROW __nonnull ((1, 2));
  356. extern int srandom_r (unsigned int __seed, struct random_data *__buf)
  357. __THROW __nonnull ((2));
  358. extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
  359. size_t __statelen,
  360. struct random_data *__restrict __buf)
  361. __THROW __nonnull ((2, 4));
  362. extern int setstate_r (char *__restrict __statebuf,
  363. struct random_data *__restrict __buf)
  364. __THROW __nonnull ((1, 2));
  365. # endif /* Use misc. */
  366. #endif /* Use extended X/Open || misc. */
  367. /* Return a random integer between 0 and RAND_MAX inclusive. */
  368. extern int rand (void) __THROW;
  369. /* Seed the random number generator with the given number. */
  370. extern void srand (unsigned int __seed) __THROW;
  371. #ifdef __USE_POSIX199506
  372. /* Reentrant interface according to POSIX.1. */
  373. extern int rand_r (unsigned int *__seed) __THROW;
  374. #endif
  375. #if defined __USE_MISC || defined __USE_XOPEN
  376. /* System V style 48-bit random number generator functions. */
  377. /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
  378. extern double drand48 (void) __THROW;
  379. extern double erand48 (unsigned short int __xsubi[3]) __THROW __nonnull ((1));
  380. /* Return non-negative, long integer in [0,2^31). */
  381. extern long int lrand48 (void) __THROW;
  382. extern long int nrand48 (unsigned short int __xsubi[3])
  383. __THROW __nonnull ((1));
  384. /* Return signed, long integers in [-2^31,2^31). */
  385. extern long int mrand48 (void) __THROW;
  386. extern long int jrand48 (unsigned short int __xsubi[3])
  387. __THROW __nonnull ((1));
  388. /* Seed random number generator. */
  389. extern void srand48 (long int __seedval) __THROW;
  390. extern unsigned short int *seed48 (unsigned short int __seed16v[3])
  391. __THROW __nonnull ((1));
  392. extern void lcong48 (unsigned short int __param[7]) __THROW __nonnull ((1));
  393. # ifdef __USE_MISC
  394. /* Data structure for communication with thread safe versions. This
  395. type is to be regarded as opaque. It's only exported because users
  396. have to allocate objects of this type. */
  397. struct drand48_data
  398. {
  399. unsigned short int __x[3]; /* Current state. */
  400. unsigned short int __old_x[3]; /* Old state. */
  401. unsigned short int __c; /* Additive const. in congruential formula. */
  402. unsigned short int __init; /* Flag for initializing. */
  403. __extension__ unsigned long long int __a; /* Factor in congruential
  404. formula. */
  405. };
  406. /* Return non-negative, double-precision floating-point value in [0.0,1.0). */
  407. extern int drand48_r (struct drand48_data *__restrict __buffer,
  408. double *__restrict __result) __THROW __nonnull ((1, 2));
  409. extern int erand48_r (unsigned short int __xsubi[3],
  410. struct drand48_data *__restrict __buffer,
  411. double *__restrict __result) __THROW __nonnull ((1, 2));
  412. /* Return non-negative, long integer in [0,2^31). */
  413. extern int lrand48_r (struct drand48_data *__restrict __buffer,
  414. long int *__restrict __result)
  415. __THROW __nonnull ((1, 2));
  416. extern int nrand48_r (unsigned short int __xsubi[3],
  417. struct drand48_data *__restrict __buffer,
  418. long int *__restrict __result)
  419. __THROW __nonnull ((1, 2));
  420. /* Return signed, long integers in [-2^31,2^31). */
  421. extern int mrand48_r (struct drand48_data *__restrict __buffer,
  422. long int *__restrict __result)
  423. __THROW __nonnull ((1, 2));
  424. extern int jrand48_r (unsigned short int __xsubi[3],
  425. struct drand48_data *__restrict __buffer,
  426. long int *__restrict __result)
  427. __THROW __nonnull ((1, 2));
  428. /* Seed random number generator. */
  429. extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
  430. __THROW __nonnull ((2));
  431. extern int seed48_r (unsigned short int __seed16v[3],
  432. struct drand48_data *__buffer) __THROW __nonnull ((1, 2));
  433. extern int lcong48_r (unsigned short int __param[7],
  434. struct drand48_data *__buffer)
  435. __THROW __nonnull ((1, 2));
  436. # endif /* Use misc. */
  437. #endif /* Use misc or X/Open. */
  438. /* Allocate SIZE bytes of memory. */
  439. extern void *malloc (size_t __size) __THROW __attribute_malloc__
  440. __attribute_alloc_size__ ((1)) __wur;
  441. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
  442. extern void *calloc (size_t __nmemb, size_t __size)
  443. __THROW __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __wur;
  444. /* Re-allocate the previously allocated block
  445. in PTR, making the new block SIZE bytes long. */
  446. /* __attribute_malloc__ is not used, because if realloc returns
  447. the same pointer that was passed to it, aliasing needs to be allowed
  448. between objects pointed by the old and new pointers. */
  449. extern void *realloc (void *__ptr, size_t __size)
  450. __THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2));
  451. #ifdef __USE_MISC
  452. /* Re-allocate the previously allocated block in PTR, making the new
  453. block large enough for NMEMB elements of SIZE bytes each. */
  454. /* __attribute_malloc__ is not used, because if reallocarray returns
  455. the same pointer that was passed to it, aliasing needs to be allowed
  456. between objects pointed by the old and new pointers. */
  457. extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)
  458. __THROW __attribute_warn_unused_result__
  459. __attribute_alloc_size__ ((2, 3));
  460. #endif
  461. /* Free a block allocated by `malloc', `realloc' or `calloc'. */
  462. extern void free (void *__ptr) __THROW;
  463. #ifdef __USE_MISC
  464. # include <alloca.h>
  465. #endif /* Use misc. */
  466. #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \
  467. || defined __USE_MISC
  468. /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
  469. extern void *valloc (size_t __size) __THROW __attribute_malloc__
  470. __attribute_alloc_size__ ((1)) __wur;
  471. #endif
  472. #ifdef __USE_XOPEN2K
  473. /* Allocate memory of SIZE bytes with an alignment of ALIGNMENT. */
  474. extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
  475. __THROW __nonnull ((1)) __wur;
  476. #endif
  477. #ifdef __USE_ISOC11
  478. /* ISO C variant of aligned allocation. */
  479. extern void *aligned_alloc (size_t __alignment, size_t __size)
  480. __THROW __attribute_malloc__ __attribute_alloc_size__ ((2)) __wur;
  481. #endif
  482. /* Abort execution and generate a core-dump. */
  483. extern void abort (void) __THROW __attribute__ ((__noreturn__));
  484. /* Register a function to be called when `exit' is called. */
  485. extern int atexit (void (*__func) (void)) __THROW __nonnull ((1));
  486. #if defined __USE_ISOC11 || defined __USE_ISOCXX11
  487. /* Register a function to be called when `quick_exit' is called. */
  488. # ifdef __cplusplus
  489. extern "C++" int at_quick_exit (void (*__func) (void))
  490. __THROW __asm ("at_quick_exit") __nonnull ((1));
  491. # else
  492. extern int at_quick_exit (void (*__func) (void)) __THROW __nonnull ((1));
  493. # endif
  494. #endif
  495. #ifdef __USE_MISC
  496. /* Register a function to be called with the status
  497. given to `exit' and the given argument. */
  498. extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
  499. __THROW __nonnull ((1));
  500. #endif
  501. /* Call all functions registered with `atexit' and `on_exit',
  502. in the reverse of the order in which they were registered,
  503. perform stdio cleanup, and terminate program execution with STATUS. */
  504. extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
  505. #if defined __USE_ISOC11 || defined __USE_ISOCXX11
  506. /* Call all functions registered with `at_quick_exit' in the reverse
  507. of the order in which they were registered and terminate program
  508. execution with STATUS. */
  509. extern void quick_exit (int __status) __THROW __attribute__ ((__noreturn__));
  510. #endif
  511. #ifdef __USE_ISOC99
  512. /* Terminate the program with STATUS without calling any of the
  513. functions registered with `atexit' or `on_exit'. */
  514. extern void _Exit (int __status) __THROW __attribute__ ((__noreturn__));
  515. #endif
  516. /* Return the value of envariable NAME, or NULL if it doesn't exist. */
  517. extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;
  518. #ifdef __USE_GNU
  519. /* This function is similar to the above but returns NULL if the
  520. programs is running with SUID or SGID enabled. */
  521. extern char *secure_getenv (const char *__name)
  522. __THROW __nonnull ((1)) __wur;
  523. #endif
  524. #if defined __USE_MISC || defined __USE_XOPEN
  525. /* The SVID says this is in <stdio.h>, but this seems a better place. */
  526. /* Put STRING, which is of the form "NAME=VALUE", in the environment.
  527. If there is no `=', remove NAME from the environment. */
  528. extern int putenv (char *__string) __THROW __nonnull ((1));
  529. #endif
  530. #ifdef __USE_XOPEN2K
  531. /* Set NAME to VALUE in the environment.
  532. If REPLACE is nonzero, overwrite an existing value. */
  533. extern int setenv (const char *__name, const char *__value, int __replace)
  534. __THROW __nonnull ((2));
  535. /* Remove the variable NAME from the environment. */
  536. extern int unsetenv (const char *__name) __THROW __nonnull ((1));
  537. #endif
  538. #ifdef __USE_MISC
  539. /* The `clearenv' was planned to be added to POSIX.1 but probably
  540. never made it. Nevertheless the POSIX.9 standard (POSIX bindings
  541. for Fortran 77) requires this function. */
  542. extern int clearenv (void) __THROW;
  543. #endif
  544. #if defined __USE_MISC \
  545. || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8)
  546. /* Generate a unique temporary file name from TEMPLATE.
  547. The last six characters of TEMPLATE must be "XXXXXX";
  548. they are replaced with a string that makes the file name unique.
  549. Always returns TEMPLATE, it's either a temporary file name or a null
  550. string if it cannot get a unique file name. */
  551. extern char *mktemp (char *__template) __THROW __nonnull ((1));
  552. #endif
  553. #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
  554. /* Generate a unique temporary file name from TEMPLATE.
  555. The last six characters of TEMPLATE must be "XXXXXX";
  556. they are replaced with a string that makes the filename unique.
  557. Returns a file descriptor open on the file for reading and writing,
  558. or -1 if it cannot create a uniquely-named file.
  559. This function is a possible cancellation point and therefore not
  560. marked with __THROW. */
  561. # ifndef __USE_FILE_OFFSET64
  562. extern int mkstemp (char *__template) __nonnull ((1)) __wur;
  563. # else
  564. # ifdef __REDIRECT
  565. extern int __REDIRECT (mkstemp, (char *__template), mkstemp64)
  566. __nonnull ((1)) __wur;
  567. # else
  568. # define mkstemp mkstemp64
  569. # endif
  570. # endif
  571. # ifdef __USE_LARGEFILE64
  572. extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
  573. # endif
  574. #endif
  575. #ifdef __USE_MISC
  576. /* Similar to mkstemp, but the template can have a suffix after the
  577. XXXXXX. The length of the suffix is specified in the second
  578. parameter.
  579. This function is a possible cancellation point and therefore not
  580. marked with __THROW. */
  581. # ifndef __USE_FILE_OFFSET64
  582. extern int mkstemps (char *__template, int __suffixlen) __nonnull ((1)) __wur;
  583. # else
  584. # ifdef __REDIRECT
  585. extern int __REDIRECT (mkstemps, (char *__template, int __suffixlen),
  586. mkstemps64) __nonnull ((1)) __wur;
  587. # else
  588. # define mkstemps mkstemps64
  589. # endif
  590. # endif
  591. # ifdef __USE_LARGEFILE64
  592. extern int mkstemps64 (char *__template, int __suffixlen)
  593. __nonnull ((1)) __wur;
  594. # endif
  595. #endif
  596. #ifdef __USE_XOPEN2K8
  597. /* Create a unique temporary directory from TEMPLATE.
  598. The last six characters of TEMPLATE must be "XXXXXX";
  599. they are replaced with a string that makes the directory name unique.
  600. Returns TEMPLATE, or a null pointer if it cannot get a unique name.
  601. The directory is created mode 700. */
  602. extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
  603. #endif
  604. #ifdef __USE_GNU
  605. /* Generate a unique temporary file name from TEMPLATE similar to
  606. mkstemp. But allow the caller to pass additional flags which are
  607. used in the open call to create the file..
  608. This function is a possible cancellation point and therefore not
  609. marked with __THROW. */
  610. # ifndef __USE_FILE_OFFSET64
  611. extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur;
  612. # else
  613. # ifdef __REDIRECT
  614. extern int __REDIRECT (mkostemp, (char *__template, int __flags), mkostemp64)
  615. __nonnull ((1)) __wur;
  616. # else
  617. # define mkostemp mkostemp64
  618. # endif
  619. # endif
  620. # ifdef __USE_LARGEFILE64
  621. extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur;
  622. # endif
  623. /* Similar to mkostemp, but the template can have a suffix after the
  624. XXXXXX. The length of the suffix is specified in the second
  625. parameter.
  626. This function is a possible cancellation point and therefore not
  627. marked with __THROW. */
  628. # ifndef __USE_FILE_OFFSET64
  629. extern int mkostemps (char *__template, int __suffixlen, int __flags)
  630. __nonnull ((1)) __wur;
  631. # else
  632. # ifdef __REDIRECT
  633. extern int __REDIRECT (mkostemps, (char *__template, int __suffixlen,
  634. int __flags), mkostemps64)
  635. __nonnull ((1)) __wur;
  636. # else
  637. # define mkostemps mkostemps64
  638. # endif
  639. # endif
  640. # ifdef __USE_LARGEFILE64
  641. extern int mkostemps64 (char *__template, int __suffixlen, int __flags)
  642. __nonnull ((1)) __wur;
  643. # endif
  644. #endif
  645. /* Execute the given line as a shell command.
  646. This function is a cancellation point and therefore not marked with
  647. __THROW. */
  648. extern int system (const char *__command) __wur;
  649. #ifdef __USE_GNU
  650. /* Return a malloc'd string containing the canonical absolute name of the
  651. existing named file. */
  652. extern char *canonicalize_file_name (const char *__name)
  653. __THROW __nonnull ((1)) __wur;
  654. #endif
  655. #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
  656. /* Return the canonical absolute name of file NAME. If RESOLVED is
  657. null, the result is malloc'd; otherwise, if the canonical name is
  658. PATH_MAX chars or more, returns null with `errno' set to
  659. ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
  660. returns the name in RESOLVED. */
  661. extern char *realpath (const char *__restrict __name,
  662. char *__restrict __resolved) __THROW __wur;
  663. #endif
  664. /* Shorthand for type of comparison functions. */
  665. #ifndef __COMPAR_FN_T
  666. # define __COMPAR_FN_T
  667. typedef int (*__compar_fn_t) (const void *, const void *);
  668. # ifdef __USE_GNU
  669. typedef __compar_fn_t comparison_fn_t;
  670. # endif
  671. #endif
  672. #ifdef __USE_GNU
  673. typedef int (*__compar_d_fn_t) (const void *, const void *, void *);
  674. #endif
  675. /* Do a binary search for KEY in BASE, which consists of NMEMB elements
  676. of SIZE bytes each, using COMPAR to perform the comparisons. */
  677. extern void *bsearch (const void *__key, const void *__base,
  678. size_t __nmemb, size_t __size, __compar_fn_t __compar)
  679. __nonnull ((1, 2, 5)) __wur;
  680. #ifdef __USE_EXTERN_INLINES
  681. # include <bits/stdlib-bsearch.h>
  682. #endif
  683. /* Sort NMEMB elements of BASE, of SIZE bytes each,
  684. using COMPAR to perform the comparisons. */
  685. extern void qsort (void *__base, size_t __nmemb, size_t __size,
  686. __compar_fn_t __compar) __nonnull ((1, 4));
  687. #ifdef __USE_GNU
  688. extern void qsort_r (void *__base, size_t __nmemb, size_t __size,
  689. __compar_d_fn_t __compar, void *__arg)
  690. __nonnull ((1, 4));
  691. #endif
  692. /* Return the absolute value of X. */
  693. extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
  694. extern long int labs (long int __x) __THROW __attribute__ ((__const__)) __wur;
  695. #ifdef __USE_ISOC99
  696. __extension__ extern long long int llabs (long long int __x)
  697. __THROW __attribute__ ((__const__)) __wur;
  698. #endif
  699. /* Return the `div_t', `ldiv_t' or `lldiv_t' representation
  700. of the value of NUMER over DENOM. */
  701. /* GCC may have built-ins for these someday. */
  702. extern div_t div (int __numer, int __denom)
  703. __THROW __attribute__ ((__const__)) __wur;
  704. extern ldiv_t ldiv (long int __numer, long int __denom)
  705. __THROW __attribute__ ((__const__)) __wur;
  706. #ifdef __USE_ISOC99
  707. __extension__ extern lldiv_t lldiv (long long int __numer,
  708. long long int __denom)
  709. __THROW __attribute__ ((__const__)) __wur;
  710. #endif
  711. #if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \
  712. || defined __USE_MISC
  713. /* Convert floating point numbers to strings. The returned values are
  714. valid only until another call to the same function. */
  715. /* Convert VALUE to a string with NDIGIT digits and return a pointer to
  716. this. Set *DECPT with the position of the decimal character and *SIGN
  717. with the sign of the number. */
  718. extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
  719. int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
  720. /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
  721. with the position of the decimal character and *SIGN with the sign of
  722. the number. */
  723. extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
  724. int *__restrict __sign) __THROW __nonnull ((3, 4)) __wur;
  725. /* If possible convert VALUE to a string with NDIGIT significant digits.
  726. Otherwise use exponential representation. The resulting string will
  727. be written to BUF. */
  728. extern char *gcvt (double __value, int __ndigit, char *__buf)
  729. __THROW __nonnull ((3)) __wur;
  730. #endif
  731. #ifdef __USE_MISC
  732. /* Long double versions of above functions. */
  733. extern char *qecvt (long double __value, int __ndigit,
  734. int *__restrict __decpt, int *__restrict __sign)
  735. __THROW __nonnull ((3, 4)) __wur;
  736. extern char *qfcvt (long double __value, int __ndigit,
  737. int *__restrict __decpt, int *__restrict __sign)
  738. __THROW __nonnull ((3, 4)) __wur;
  739. extern char *qgcvt (long double __value, int __ndigit, char *__buf)
  740. __THROW __nonnull ((3)) __wur;
  741. /* Reentrant version of the functions above which provide their own
  742. buffers. */
  743. extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
  744. int *__restrict __sign, char *__restrict __buf,
  745. size_t __len) __THROW __nonnull ((3, 4, 5));
  746. extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
  747. int *__restrict __sign, char *__restrict __buf,
  748. size_t __len) __THROW __nonnull ((3, 4, 5));
  749. extern int qecvt_r (long double __value, int __ndigit,
  750. int *__restrict __decpt, int *__restrict __sign,
  751. char *__restrict __buf, size_t __len)
  752. __THROW __nonnull ((3, 4, 5));
  753. extern int qfcvt_r (long double __value, int __ndigit,
  754. int *__restrict __decpt, int *__restrict __sign,
  755. char *__restrict __buf, size_t __len)
  756. __THROW __nonnull ((3, 4, 5));
  757. #endif /* misc */
  758. /* Return the length of the multibyte character
  759. in S, which is no longer than N. */
  760. extern int mblen (const char *__s, size_t __n) __THROW;
  761. /* Return the length of the given multibyte character,
  762. putting its `wchar_t' representation in *PWC. */
  763. extern int mbtowc (wchar_t *__restrict __pwc,
  764. const char *__restrict __s, size_t __n) __THROW;
  765. /* Put the multibyte character represented
  766. by WCHAR in S, returning its length. */
  767. extern int wctomb (char *__s, wchar_t __wchar) __THROW;
  768. /* Convert a multibyte string to a wide char string. */
  769. extern size_t mbstowcs (wchar_t *__restrict __pwcs,
  770. const char *__restrict __s, size_t __n) __THROW;
  771. /* Convert a wide char string to multibyte string. */
  772. extern size_t wcstombs (char *__restrict __s,
  773. const wchar_t *__restrict __pwcs, size_t __n)
  774. __THROW;
  775. #ifdef __USE_MISC
  776. /* Determine whether the string value of RESPONSE matches the affirmation
  777. or negative response expression as specified by the LC_MESSAGES category
  778. in the program's current locale. Returns 1 if affirmative, 0 if
  779. negative, and -1 if not matching. */
  780. extern int rpmatch (const char *__response) __THROW __nonnull ((1)) __wur;
  781. #endif
  782. #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
  783. /* Parse comma separated suboption from *OPTIONP and match against
  784. strings in TOKENS. If found return index and set *VALUEP to
  785. optional value introduced by an equal sign. If the suboption is
  786. not part of TOKENS return in *VALUEP beginning of unknown
  787. suboption. On exit *OPTIONP is set to the beginning of the next
  788. token or at the terminating NUL character. */
  789. extern int getsubopt (char **__restrict __optionp,
  790. char *const *__restrict __tokens,
  791. char **__restrict __valuep)
  792. __THROW __nonnull ((1, 2, 3)) __wur;
  793. #endif
  794. /* X/Open pseudo terminal handling. */
  795. #ifdef __USE_XOPEN2KXSI
  796. /* Return a master pseudo-terminal handle. */
  797. extern int posix_openpt (int __oflag) __wur;
  798. #endif
  799. #ifdef __USE_XOPEN_EXTENDED
  800. /* The next four functions all take a master pseudo-tty fd and
  801. perform an operation on the associated slave: */
  802. /* Chown the slave to the calling user. */
  803. extern int grantpt (int __fd) __THROW;
  804. /* Release an internal lock so the slave can be opened.
  805. Call after grantpt(). */
  806. extern int unlockpt (int __fd) __THROW;
  807. /* Return the pathname of the pseudo terminal slave associated with
  808. the master FD is open on, or NULL on errors.
  809. The returned storage is good until the next call to this function. */
  810. extern char *ptsname (int __fd) __THROW __wur;
  811. #endif
  812. #ifdef __USE_GNU
  813. /* Store at most BUFLEN characters of the pathname of the slave pseudo
  814. terminal associated with the master FD is open on in BUF.
  815. Return 0 on success, otherwise an error number. */
  816. extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
  817. __THROW __nonnull ((2));
  818. /* Open a master pseudo terminal and return its file descriptor. */
  819. extern int getpt (void);
  820. #endif
  821. #ifdef __USE_MISC
  822. /* Put the 1 minute, 5 minute and 15 minute load averages into the first
  823. NELEM elements of LOADAVG. Return the number written (never more than
  824. three, but may be less than NELEM), or -1 if an error occurred. */
  825. extern int getloadavg (double __loadavg[], int __nelem)
  826. __THROW __nonnull ((1));
  827. #endif
  828. #if defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K
  829. /* Return the index into the active-logins file (utmp) for
  830. the controlling terminal. */
  831. extern int ttyslot (void) __THROW;
  832. #endif
  833. #include <bits/stdlib-float.h>
  834. /* Define some macros helping to catch buffer overflows. */
  835. #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
  836. # include <bits/stdlib.h>
  837. #endif
  838. #ifdef __LDBL_COMPAT
  839. # include <bits/stdlib-ldbl.h>
  840. #endif
  841. __END_DECLS
  842. #endif /* stdlib.h */