stdlib.h 42 KB

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