stdlib.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. #ifndef _STDLIB_H
  2. #ifndef _ISOMAC
  3. # include <stdbool.h>
  4. # include <stddef.h>
  5. #endif
  6. /* Workaround PR90731 with GCC 9 when using ldbl redirects in C++. */
  7. #include <bits/floatn.h>
  8. #if defined __cplusplus && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  9. # if __GNUC_PREREQ (9, 0) && !__GNUC_PREREQ (9, 3)
  10. # pragma GCC system_header
  11. # endif
  12. #endif
  13. #include <stdlib/stdlib.h>
  14. /* Now define the internal interfaces. */
  15. #if !defined _ISOMAC
  16. # include <sys/stat.h>
  17. # include <rtld-malloc.h>
  18. # include <internal-sigset.h>
  19. extern __typeof (strtol_l) __strtol_l;
  20. extern __typeof (strtoul_l) __strtoul_l;
  21. extern __typeof (strtoll_l) __strtoll_l;
  22. extern __typeof (strtoull_l) __strtoull_l;
  23. extern __typeof (strtod_l) __strtod_l;
  24. extern __typeof (strtof_l) __strtof_l;
  25. extern __typeof (strtold_l) __strtold_l;
  26. libc_hidden_proto (__strtol_l)
  27. libc_hidden_proto (__strtoul_l)
  28. libc_hidden_proto (__strtoll_l)
  29. libc_hidden_proto (__strtoull_l)
  30. libc_hidden_proto (__strtod_l)
  31. libc_hidden_proto (__strtof_l)
  32. libc_hidden_proto (__strtold_l)
  33. extern __typeof (strtol) __isoc23_strtol __attribute_copy__ (strtol);
  34. extern __typeof (strtoul) __isoc23_strtoul __attribute_copy__ (strtoul);
  35. extern __typeof (strtoll) __isoc23_strtoll __attribute_copy__ (strtoll);
  36. extern __typeof (strtoull) __isoc23_strtoull __attribute_copy__ (strtoull);
  37. extern __typeof (strtol_l) __isoc23_strtol_l __attribute_copy__ (strtol_l);
  38. extern __typeof (strtoul_l) __isoc23_strtoul_l __attribute_copy__ (strtoul_l);
  39. extern __typeof (strtoll_l) __isoc23_strtoll_l __attribute_copy__ (strtoll_l);
  40. extern __typeof (strtoull_l) __isoc23_strtoull_l __attribute_copy__ (strtoull_l);
  41. libc_hidden_proto (__isoc23_strtol)
  42. libc_hidden_proto (__isoc23_strtoul)
  43. libc_hidden_proto (__isoc23_strtoll)
  44. libc_hidden_proto (__isoc23_strtoull)
  45. libc_hidden_proto (__isoc23_strtol_l)
  46. libc_hidden_proto (__isoc23_strtoul_l)
  47. libc_hidden_proto (__isoc23_strtoll_l)
  48. libc_hidden_proto (__isoc23_strtoull_l)
  49. #if __GLIBC_USE (C23_STRTOL)
  50. /* Redirect internal uses of these functions to the C23 versions; the
  51. redirection in the installed header does not work with
  52. libc_hidden_proto. */
  53. # undef strtol
  54. # define strtol __isoc23_strtol
  55. # undef atoi
  56. # define atoi(nptr) __isoc23_strtol(nptr, NULL, 10)
  57. # undef strtoul
  58. # define strtoul __isoc23_strtoul
  59. # undef strtoll
  60. # define strtoll __isoc23_strtoll
  61. # undef strtoull
  62. # define strtoull __isoc23_strtoull
  63. # undef strtol_l
  64. # define strtol_l __isoc23_strtol_l
  65. # undef strtoul_l
  66. # define strtoul_l __isoc23_strtoul_l
  67. # undef strtoll_l
  68. # define strtoll_l __isoc23_strtoll_l
  69. # undef strtoull_l
  70. # define strtoull_l __isoc23_strtoull_l
  71. #endif
  72. extern void __abort_fork_reset_child (void) attribute_hidden;
  73. extern void __abort_lock_rdlock (internal_sigset_t *set) attribute_hidden;
  74. extern void __abort_lock_wrlock (internal_sigset_t *set) attribute_hidden;
  75. extern void __abort_lock_unlock (const internal_sigset_t *set)
  76. attribute_hidden;
  77. libc_hidden_proto (exit)
  78. libc_hidden_proto (abort)
  79. libc_hidden_proto (getenv)
  80. extern __typeof (secure_getenv) __libc_secure_getenv;
  81. libc_hidden_proto (__libc_secure_getenv)
  82. libc_hidden_proto (bsearch)
  83. libc_hidden_proto (qsort)
  84. extern __typeof (qsort_r) __qsort_r;
  85. libc_hidden_proto (__qsort_r)
  86. libc_hidden_proto (lrand48_r)
  87. libc_hidden_proto (wctomb)
  88. extern long int __random (void) attribute_hidden;
  89. extern void __srandom (unsigned int __seed);
  90. extern char *__initstate (unsigned int __seed, char *__statebuf,
  91. size_t __statelen);
  92. extern char *__setstate (char *__statebuf);
  93. extern int __random_r (struct random_data *__buf, int32_t *__result)
  94. attribute_hidden;
  95. extern int __srandom_r (unsigned int __seed, struct random_data *__buf)
  96. attribute_hidden;
  97. extern int __initstate_r (unsigned int __seed, char *__statebuf,
  98. size_t __statelen, struct random_data *__buf)
  99. attribute_hidden;
  100. extern int __setstate_r (char *__statebuf, struct random_data *__buf)
  101. attribute_hidden;
  102. extern int __rand_r (unsigned int *__seed);
  103. extern int __erand48_r (unsigned short int __xsubi[3],
  104. struct drand48_data *__buffer, double *__result)
  105. attribute_hidden;
  106. extern int __nrand48_r (unsigned short int __xsubi[3],
  107. struct drand48_data *__buffer,
  108. long int *__result) attribute_hidden;
  109. extern int __jrand48_r (unsigned short int __xsubi[3],
  110. struct drand48_data *__buffer,
  111. long int *__result) attribute_hidden;
  112. extern int __srand48_r (long int __seedval,
  113. struct drand48_data *__buffer) attribute_hidden;
  114. extern int __seed48_r (unsigned short int __seed16v[3],
  115. struct drand48_data *__buffer) attribute_hidden;
  116. extern int __lcong48_r (unsigned short int __param[7],
  117. struct drand48_data *__buffer) attribute_hidden;
  118. /* Internal function to compute next state of the generator. */
  119. extern int __drand48_iterate (unsigned short int __xsubi[3],
  120. struct drand48_data *__buffer)
  121. attribute_hidden;
  122. /* Global state for non-reentrant functions. Defined in drand48-iter.c. */
  123. extern struct drand48_data __libc_drand48_data attribute_hidden;
  124. extern int __setenv (const char *__name, const char *__value, int __replace)
  125. attribute_hidden;
  126. extern int __unsetenv (const char *__name) attribute_hidden;
  127. extern int __clearenv (void) attribute_hidden;
  128. extern char *__mktemp (char *__template) __THROW __nonnull ((1));
  129. libc_hidden_proto (__mktemp)
  130. extern char *__canonicalize_file_name (const char *__name);
  131. extern char *__realpath (const char *__name, char *__resolved);
  132. libc_hidden_proto (__realpath)
  133. extern int __ptsname_r (int __fd, char *__buf, size_t __buflen)
  134. attribute_hidden;
  135. # ifndef _ISOMAC
  136. extern int __ptsname_internal (int fd, char *buf, size_t buflen,
  137. struct stat64 *stp) attribute_hidden;
  138. # endif
  139. extern int __getpt (void);
  140. extern int __posix_openpt (int __oflag) attribute_hidden;
  141. extern int __add_to_environ (const char *name, const char *value,
  142. const char *combines, int replace)
  143. attribute_hidden;
  144. extern int __on_exit (void (*__func) (int __status, void *__arg), void *__arg);
  145. extern int __cxa_atexit (void (*func) (void *), void *arg, void *d);
  146. libc_hidden_proto (__cxa_atexit);
  147. extern int __cxa_thread_atexit_impl (void (*func) (void *), void *arg,
  148. void *d);
  149. extern void __call_tls_dtors (void);
  150. libc_hidden_proto (__call_tls_dtors)
  151. extern void __cxa_finalize (void *d);
  152. extern int __posix_memalign (void **memptr, size_t alignment, size_t size);
  153. extern void *__libc_memalign (size_t alignment, size_t size)
  154. __attribute_malloc__;
  155. extern void *__libc_reallocarray (void *__ptr, size_t __nmemb, size_t __size)
  156. __THROW __attribute_warn_unused_result__;
  157. libc_hidden_proto (__libc_reallocarray)
  158. extern int __libc_system (const char *line);
  159. extern __typeof (getpt) __getpt;
  160. extern __typeof (ptsname_r) __ptsname_r;
  161. libc_hidden_proto (__getpt)
  162. libc_hidden_proto (__ptsname_r)
  163. libc_hidden_proto (grantpt)
  164. libc_hidden_proto (unlockpt)
  165. __typeof (arc4random) __arc4random;
  166. libc_hidden_proto (__arc4random);
  167. __typeof (arc4random_buf) __arc4random_buf;
  168. libc_hidden_proto (__arc4random_buf);
  169. __typeof (arc4random_uniform) __arc4random_uniform;
  170. libc_hidden_proto (__arc4random_uniform);
  171. extern void __arc4random_buf_internal (void *buffer, size_t len)
  172. attribute_hidden;
  173. extern double __strtod_internal (const char *__restrict __nptr,
  174. char **__restrict __endptr, int __group)
  175. __THROW __nonnull ((1)) __wur;
  176. extern float __strtof_internal (const char *__restrict __nptr,
  177. char **__restrict __endptr, int __group)
  178. __THROW __nonnull ((1)) __wur;
  179. extern long double __strtold_internal (const char *__restrict __nptr,
  180. char **__restrict __endptr,
  181. int __group)
  182. __THROW __nonnull ((1)) __wur;
  183. extern long int __strtol_internal (const char *__restrict __nptr,
  184. char **__restrict __endptr,
  185. int __base, int __group)
  186. __THROW __nonnull ((1)) __wur;
  187. extern unsigned long int __strtoul_internal (const char *__restrict __nptr,
  188. char **__restrict __endptr,
  189. int __base, int __group)
  190. __THROW __nonnull ((1)) __wur;
  191. __extension__
  192. extern long long int __strtoll_internal (const char *__restrict __nptr,
  193. char **__restrict __endptr,
  194. int __base, int __group)
  195. __THROW __nonnull ((1)) __wur;
  196. __extension__
  197. extern unsigned long long int __strtoull_internal (const char *
  198. __restrict __nptr,
  199. char **__restrict __endptr,
  200. int __base, int __group)
  201. __THROW __nonnull ((1)) __wur;
  202. libc_hidden_proto (__strtof_internal)
  203. libc_hidden_proto (__strtod_internal)
  204. libc_hidden_proto (__strtold_internal)
  205. libc_hidden_proto (__strtol_internal)
  206. libc_hidden_proto (__strtoll_internal)
  207. libc_hidden_proto (__strtoul_internal)
  208. libc_hidden_proto (__strtoull_internal)
  209. extern double ____strtod_l_internal (const char *__restrict __nptr,
  210. char **__restrict __endptr, int __group,
  211. locale_t __loc);
  212. extern float ____strtof_l_internal (const char *__restrict __nptr,
  213. char **__restrict __endptr, int __group,
  214. locale_t __loc);
  215. extern long double ____strtold_l_internal (const char *__restrict __nptr,
  216. char **__restrict __endptr,
  217. int __group, locale_t __loc);
  218. extern long int ____strtol_l_internal (const char *__restrict __nptr,
  219. char **__restrict __endptr,
  220. int __base, int __group,
  221. bool __bin_cst, locale_t __loc);
  222. extern unsigned long int ____strtoul_l_internal (const char *
  223. __restrict __nptr,
  224. char **__restrict __endptr,
  225. int __base, int __group,
  226. bool __bin_cst,
  227. locale_t __loc);
  228. __extension__
  229. extern long long int ____strtoll_l_internal (const char *__restrict __nptr,
  230. char **__restrict __endptr,
  231. int __base, int __group,
  232. bool __bin_cst, locale_t __loc);
  233. __extension__
  234. extern unsigned long long int ____strtoull_l_internal (const char *
  235. __restrict __nptr,
  236. char **
  237. __restrict __endptr,
  238. int __base, int __group,
  239. bool __bin_cst,
  240. locale_t __loc);
  241. libc_hidden_proto (____strtof_l_internal)
  242. libc_hidden_proto (____strtod_l_internal)
  243. libc_hidden_proto (____strtold_l_internal)
  244. libc_hidden_proto (____strtol_l_internal)
  245. libc_hidden_proto (____strtoll_l_internal)
  246. libc_hidden_proto (____strtoul_l_internal)
  247. libc_hidden_proto (____strtoull_l_internal)
  248. #include <bits/floatn.h>
  249. libc_hidden_proto (strtof)
  250. libc_hidden_proto (strtod)
  251. #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
  252. libc_hidden_proto (strtold)
  253. #endif
  254. libc_hidden_proto (strtol)
  255. libc_hidden_proto (strtoll)
  256. libc_hidden_proto (strtoul)
  257. libc_hidden_proto (strtoull)
  258. libc_hidden_proto (atoi)
  259. extern float __strtof_nan (const char *, char **, char);
  260. extern double __strtod_nan (const char *, char **, char);
  261. extern long double __strtold_nan (const char *, char **, char);
  262. extern float __wcstof_nan (const wchar_t *, wchar_t **, wchar_t);
  263. extern double __wcstod_nan (const wchar_t *, wchar_t **, wchar_t);
  264. extern long double __wcstold_nan (const wchar_t *, wchar_t **, wchar_t);
  265. libc_hidden_proto (__strtof_nan)
  266. libc_hidden_proto (__strtod_nan)
  267. libc_hidden_proto (__strtold_nan)
  268. libc_hidden_proto (__wcstof_nan)
  269. libc_hidden_proto (__wcstod_nan)
  270. libc_hidden_proto (__wcstold_nan)
  271. /* Enable _FloatN bits as needed. */
  272. #include <bits/floatn.h>
  273. #if __HAVE_DISTINCT_FLOAT128
  274. extern __typeof (strtof128_l) __strtof128_l;
  275. libc_hidden_proto (__strtof128_l)
  276. libc_hidden_proto (strtof128)
  277. extern _Float128 __strtof128_nan (const char *, char **, char);
  278. extern _Float128 __wcstof128_nan (const wchar_t *, wchar_t **, wchar_t);
  279. libc_hidden_proto (__strtof128_nan)
  280. libc_hidden_proto (__wcstof128_nan)
  281. extern _Float128 __strtof128_internal (const char *__restrict __nptr,
  282. char **__restrict __endptr,
  283. int __group);
  284. libc_hidden_proto (__strtof128_internal)
  285. extern _Float128 ____strtof128_l_internal (const char *__restrict __nptr,
  286. char **__restrict __endptr,
  287. int __group, locale_t __loc);
  288. libc_hidden_proto (____strtof128_l_internal)
  289. #endif
  290. extern char *__ecvt (double __value, int __ndigit, int *__restrict __decpt,
  291. int *__restrict __sign);
  292. extern char *__fcvt (double __value, int __ndigit, int *__restrict __decpt,
  293. int *__restrict __sign);
  294. extern char *__gcvt (double __value, int __ndigit, char *__buf);
  295. extern int __ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
  296. int *__restrict __sign, char *__restrict __buf,
  297. size_t __len);
  298. libc_hidden_proto (__ecvt_r)
  299. extern int __fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
  300. int *__restrict __sign, char *__restrict __buf,
  301. size_t __len);
  302. libc_hidden_proto (__fcvt_r)
  303. extern char *__qecvt (long double __value, int __ndigit,
  304. int *__restrict __decpt, int *__restrict __sign);
  305. extern char *__qfcvt (long double __value, int __ndigit,
  306. int *__restrict __decpt, int *__restrict __sign);
  307. extern char *__qgcvt (long double __value, int __ndigit, char *__buf);
  308. extern int __qecvt_r (long double __value, int __ndigit,
  309. int *__restrict __decpt, int *__restrict __sign,
  310. char *__restrict __buf, size_t __len);
  311. libc_hidden_proto (__qecvt_r)
  312. extern int __qfcvt_r (long double __value, int __ndigit,
  313. int *__restrict __decpt, int *__restrict __sign,
  314. char *__restrict __buf, size_t __len);
  315. libc_hidden_proto (__qfcvt_r)
  316. # if IS_IN (libc)
  317. # undef MB_CUR_MAX
  318. # define MB_CUR_MAX (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MB_CUR_MAX))
  319. # endif
  320. struct abort_msg_s
  321. {
  322. unsigned int size;
  323. char msg[0];
  324. };
  325. extern struct abort_msg_s *__abort_msg;
  326. libc_hidden_proto (__abort_msg)
  327. enum readonly_error_type
  328. {
  329. readonly_noerror,
  330. readonly_area_writable,
  331. readonly_procfs_inaccessible,
  332. readonly_procfs_open_fail,
  333. };
  334. extern enum readonly_error_type __readonly_area (const void *ptr,
  335. size_t size)
  336. attribute_hidden;
  337. extern enum readonly_error_type __readonly_area_fallback (const void *ptr,
  338. size_t size)
  339. attribute_hidden;
  340. # if IS_IN (rtld)
  341. extern __typeof (unsetenv) unsetenv attribute_hidden;
  342. extern __typeof (__strtoul_internal) __strtoul_internal attribute_hidden;
  343. # endif
  344. #endif
  345. #endif /* include/stdlib.h */