stdlib.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /*
  2. * stdlib.h
  3. *
  4. * Definitions for common types, variables, and functions.
  5. */
  6. #ifndef _STDLIB_H_
  7. #define _STDLIB_H_
  8. #include <machine/ieeefp.h>
  9. #include "_ansi.h"
  10. #define __need_size_t
  11. #define __need_wchar_t
  12. #define __need_NULL
  13. #include <stddef.h>
  14. #include <sys/reent.h>
  15. #include <sys/cdefs.h>
  16. #include <machine/stdlib.h>
  17. #ifndef __STRICT_ANSI__
  18. #include <alloca.h>
  19. #endif
  20. #ifdef __CYGWIN__
  21. #include <cygwin/stdlib.h>
  22. #endif
  23. #if __GNU_VISIBLE
  24. #include <xlocale.h>
  25. #endif
  26. _BEGIN_STD_C
  27. typedef struct
  28. {
  29. int quot; /* quotient */
  30. int rem; /* remainder */
  31. } div_t;
  32. typedef struct
  33. {
  34. long quot; /* quotient */
  35. long rem; /* remainder */
  36. } ldiv_t;
  37. #if __ISO_C_VISIBLE >= 1999
  38. typedef struct
  39. {
  40. long long int quot; /* quotient */
  41. long long int rem; /* remainder */
  42. } lldiv_t;
  43. #endif
  44. #ifndef __compar_fn_t_defined
  45. #define __compar_fn_t_defined
  46. typedef int (*__compar_fn_t) (const void *, const void *);
  47. #endif
  48. #define EXIT_FAILURE 1
  49. #define EXIT_SUCCESS 0
  50. #define RAND_MAX __RAND_MAX
  51. int __locale_mb_cur_max (void);
  52. #define MB_CUR_MAX __locale_mb_cur_max()
  53. void abort (void) _ATTRIBUTE ((__noreturn__));
  54. int abs (int);
  55. #if __BSD_VISIBLE
  56. __uint32_t arc4random (void);
  57. __uint32_t arc4random_uniform (__uint32_t);
  58. void arc4random_buf (void *, size_t);
  59. #endif
  60. int atexit (void (*__func)(void));
  61. double atof (const char *__nptr);
  62. #if __MISC_VISIBLE
  63. float atoff (const char *__nptr);
  64. #endif
  65. int atoi (const char *__nptr);
  66. int _atoi_r (struct _reent *, const char *__nptr);
  67. long atol (const char *__nptr);
  68. long _atol_r (struct _reent *, const char *__nptr);
  69. void * bsearch (const void *__key,
  70. const void *__base,
  71. size_t __nmemb,
  72. size_t __size,
  73. __compar_fn_t _compar);
  74. void *calloc(size_t, size_t) __malloc_like __result_use_check
  75. __alloc_size2(1, 2) _NOTHROW;
  76. div_t div (int __numer, int __denom);
  77. void exit (int __status) _ATTRIBUTE ((__noreturn__));
  78. void free (void *) _NOTHROW;
  79. char * getenv (const char *__string);
  80. char * _getenv_r (struct _reent *, const char *__string);
  81. char * _findenv (const char *, int *);
  82. char * _findenv_r (struct _reent *, const char *, int *);
  83. #if __POSIX_VISIBLE >= 200809
  84. extern char *suboptarg; /* getsubopt(3) external variable */
  85. int getsubopt (char **, char * const *, char **);
  86. #endif
  87. long labs (long);
  88. ldiv_t ldiv (long __numer, long __denom);
  89. void *malloc(size_t) __malloc_like __result_use_check __alloc_size(1) _NOTHROW;
  90. int mblen (const char *, size_t);
  91. int _mblen_r (struct _reent *, const char *, size_t, _mbstate_t *);
  92. int mbtowc (wchar_t *__restrict, const char *__restrict, size_t);
  93. int _mbtowc_r (struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *);
  94. int wctomb (char *, wchar_t);
  95. int _wctomb_r (struct _reent *, char *, wchar_t, _mbstate_t *);
  96. size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t);
  97. size_t _mbstowcs_r (struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *);
  98. size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t);
  99. size_t _wcstombs_r (struct _reent *, char *__restrict, const wchar_t *__restrict, size_t, _mbstate_t *);
  100. #ifndef _REENT_ONLY
  101. #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
  102. char * mkdtemp (char *);
  103. #endif
  104. #if __GNU_VISIBLE
  105. int mkostemp (char *, int);
  106. int mkostemps (char *, int, int);
  107. #endif
  108. #if __MISC_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 4
  109. int mkstemp (char *);
  110. #endif
  111. #if __MISC_VISIBLE
  112. int mkstemps (char *, int);
  113. #endif
  114. #if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112)
  115. char * mktemp (char *) _ATTRIBUTE ((__deprecated__("the use of `mktemp' is dangerous; use `mkstemp' instead")));
  116. #endif
  117. #endif /* !_REENT_ONLY */
  118. char * _mkdtemp_r (struct _reent *, char *);
  119. int _mkostemp_r (struct _reent *, char *, int);
  120. int _mkostemps_r (struct _reent *, char *, int, int);
  121. int _mkstemp_r (struct _reent *, char *);
  122. int _mkstemps_r (struct _reent *, char *, int);
  123. char * _mktemp_r (struct _reent *, char *) _ATTRIBUTE ((__deprecated__("the use of `mktemp' is dangerous; use `mkstemp' instead")));
  124. void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t _compar);
  125. int rand (void);
  126. void *realloc(void *, size_t) __result_use_check __alloc_size(2) _NOTHROW;
  127. #if __BSD_VISIBLE
  128. void *reallocarray(void *, size_t, size_t) __result_use_check __alloc_size2(2, 3);
  129. void *reallocf(void *, size_t) __result_use_check __alloc_size(2);
  130. #endif
  131. #if __BSD_VISIBLE || __XSI_VISIBLE >= 4
  132. char * realpath (const char *__restrict path, char *__restrict resolved_path);
  133. #endif
  134. #if __BSD_VISIBLE
  135. int rpmatch (const char *response);
  136. #endif
  137. #if __XSI_VISIBLE
  138. void setkey (const char *__key);
  139. #endif
  140. void srand (unsigned __seed);
  141. double strtod (const char *__restrict __n, char **__restrict __end_PTR);
  142. double _strtod_r (struct _reent *,const char *__restrict __n, char **__restrict __end_PTR);
  143. #if __ISO_C_VISIBLE >= 1999
  144. float strtof (const char *__restrict __n, char **__restrict __end_PTR);
  145. #endif
  146. #if __MISC_VISIBLE
  147. /* the following strtodf interface is deprecated...use strtof instead */
  148. # ifndef strtodf
  149. # define strtodf strtof
  150. # endif
  151. #endif
  152. long strtol (const char *__restrict __n, char **__restrict __end_PTR, int __base);
  153. long _strtol_r (struct _reent *,const char *__restrict __n, char **__restrict __end_PTR, int __base);
  154. unsigned long strtoul (const char *__restrict __n, char **__restrict __end_PTR, int __base);
  155. unsigned long _strtoul_r (struct _reent *,const char *__restrict __n, char **__restrict __end_PTR, int __base);
  156. #if __GNU_VISIBLE
  157. double strtod_l (const char *__restrict, char **__restrict, locale_t);
  158. float strtof_l (const char *__restrict, char **__restrict, locale_t);
  159. #ifdef _HAVE_LONG_DOUBLE
  160. extern long double strtold_l (const char *__restrict, char **__restrict,
  161. locale_t);
  162. #endif /* _HAVE_LONG_DOUBLE */
  163. long strtol_l (const char *__restrict, char **__restrict, int, locale_t);
  164. unsigned long strtoul_l (const char *__restrict, char **__restrict, int,
  165. locale_t __loc);
  166. long long strtoll_l (const char *__restrict, char **__restrict, int, locale_t);
  167. unsigned long long strtoull_l (const char *__restrict, char **__restrict, int,
  168. locale_t __loc);
  169. #endif
  170. int system (const char *__string);
  171. #if __SVID_VISIBLE || __XSI_VISIBLE >= 4
  172. long a64l (const char *__input);
  173. char * l64a (long __input);
  174. char * _l64a_r (struct _reent *,long __input);
  175. #endif
  176. #if __MISC_VISIBLE
  177. int on_exit (void (*__func)(int, void *),void *__arg);
  178. #endif
  179. #if __ISO_C_VISIBLE >= 1999
  180. void _Exit (int __status) _ATTRIBUTE ((__noreturn__));
  181. #endif
  182. #if __SVID_VISIBLE || __XSI_VISIBLE
  183. int putenv (char *__string);
  184. #endif
  185. int _putenv_r (struct _reent *, char *__string);
  186. void * _reallocf_r (struct _reent *, void *, size_t);
  187. #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
  188. int setenv (const char *__string, const char *__value, int __overwrite);
  189. #endif
  190. int _setenv_r (struct _reent *, const char *__string, const char *__value, int __overwrite);
  191. #if __XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112
  192. char * gcvt (double,int,char *);
  193. char * gcvtf (float,int,char *);
  194. char * fcvt (double,int,int *,int *);
  195. char * fcvtf (float,int,int *,int *);
  196. char * ecvt (double,int,int *,int *);
  197. char * ecvtbuf (double, int, int*, int*, char *);
  198. char * fcvtbuf (double, int, int*, int*, char *);
  199. char * ecvtf (float,int,int *,int *);
  200. #endif
  201. char * __itoa (int, char *, int);
  202. char * __utoa (unsigned, char *, int);
  203. #if __MISC_VISIBLE
  204. char * itoa (int, char *, int);
  205. char * utoa (unsigned, char *, int);
  206. #endif
  207. #if __POSIX_VISIBLE
  208. int rand_r (unsigned *__seed);
  209. #endif
  210. #if __SVID_VISIBLE || __XSI_VISIBLE
  211. double drand48 (void);
  212. double _drand48_r (struct _reent *);
  213. double erand48 (unsigned short [3]);
  214. double _erand48_r (struct _reent *, unsigned short [3]);
  215. long jrand48 (unsigned short [3]);
  216. long _jrand48_r (struct _reent *, unsigned short [3]);
  217. void lcong48 (unsigned short [7]);
  218. void _lcong48_r (struct _reent *, unsigned short [7]);
  219. long lrand48 (void);
  220. long _lrand48_r (struct _reent *);
  221. long mrand48 (void);
  222. long _mrand48_r (struct _reent *);
  223. long nrand48 (unsigned short [3]);
  224. long _nrand48_r (struct _reent *, unsigned short [3]);
  225. unsigned short *
  226. seed48 (unsigned short [3]);
  227. unsigned short *
  228. _seed48_r (struct _reent *, unsigned short [3]);
  229. void srand48 (long);
  230. void _srand48_r (struct _reent *, long);
  231. #endif /* __SVID_VISIBLE || __XSI_VISIBLE */
  232. #if __SVID_VISIBLE || __XSI_VISIBLE >= 4 || __BSD_VISIBLE
  233. char * initstate (unsigned, char *, size_t);
  234. long random (void);
  235. char * setstate (char *);
  236. void srandom (unsigned);
  237. #endif
  238. #if __ISO_C_VISIBLE >= 1999
  239. long long atoll (const char *__nptr);
  240. #endif
  241. long long _atoll_r (struct _reent *, const char *__nptr);
  242. #if __ISO_C_VISIBLE >= 1999
  243. long long llabs (long long);
  244. lldiv_t lldiv (long long __numer, long long __denom);
  245. long long strtoll (const char *__restrict __n, char **__restrict __end_PTR, int __base);
  246. #endif
  247. long long _strtoll_r (struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base);
  248. #if __ISO_C_VISIBLE >= 1999
  249. unsigned long long strtoull (const char *__restrict __n, char **__restrict __end_PTR, int __base);
  250. #endif
  251. unsigned long long _strtoull_r (struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base);
  252. #ifndef __CYGWIN__
  253. #if __MISC_VISIBLE
  254. void cfree (void *);
  255. #endif
  256. #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
  257. int unsetenv (const char *__string);
  258. #endif
  259. int _unsetenv_r (struct _reent *, const char *__string);
  260. #endif /* !__CYGWIN__ */
  261. #if __POSIX_VISIBLE >= 200112
  262. int posix_memalign (void **, size_t, size_t) __nonnull((1))
  263. __result_use_check;
  264. #endif
  265. char * _dtoa_r (struct _reent *, double, int, int, int *, int*, char**);
  266. #ifdef MALLOC_PROVIDED
  267. #define _malloc_r(r, s) malloc(s)
  268. #define _free_r(r, p) free(p)
  269. #define _calloc_r(r, s1, s2) calloc(s1, s2)
  270. #define _realloc_r(r, p, s) realloc(p, s)
  271. #define _mstats_r(r, p) mstats(p)
  272. #elif !defined(__CYGWIN__)
  273. void * _malloc_r (struct _reent *, size_t) _NOTHROW;
  274. void * _calloc_r (struct _reent *, size_t, size_t) _NOTHROW;
  275. void _free_r (struct _reent *, void *) _NOTHROW;
  276. void * _realloc_r (struct _reent *, void *, size_t) _NOTHROW;
  277. void _mstats_r (struct _reent *, char *);
  278. #endif
  279. int _system_r (struct _reent *, const char *);
  280. void __eprintf (const char *, const char *, unsigned int, const char *);
  281. /* There are two common qsort_r variants. If you request
  282. _BSD_SOURCE, you get the BSD version; otherwise you get the GNU
  283. version. We want that #undef qsort_r will still let you
  284. invoke the underlying function, but that requires gcc support. */
  285. #if __GNU_VISIBLE
  286. void qsort_r (void *__base, size_t __nmemb, size_t __size, int (*_compar)(const void *, const void *, void *), void *__thunk);
  287. #elif __BSD_VISIBLE
  288. # ifdef __GNUC__
  289. void qsort_r (void *__base, size_t __nmemb, size_t __size, void *__thunk, int (*_compar)(void *, const void *, const void *))
  290. __asm__ (__ASMNAME ("__bsd_qsort_r"));
  291. # else
  292. void __bsd_qsort_r (void *__base, size_t __nmemb, size_t __size, void *__thunk, int (*_compar)(void *, const void *, const void *));
  293. # define qsort_r __bsd_qsort_r
  294. # endif
  295. #endif
  296. /* On platforms where long double equals double. */
  297. #ifdef _HAVE_LONG_DOUBLE
  298. extern long double _strtold_r (struct _reent *, const char *__restrict, char **__restrict);
  299. #if __ISO_C_VISIBLE >= 1999
  300. extern long double strtold (const char *__restrict, char **__restrict);
  301. #endif
  302. #endif /* _HAVE_LONG_DOUBLE */
  303. /*
  304. * If we're in a mode greater than C99, expose C11 functions.
  305. */
  306. #if __ISO_C_VISIBLE >= 2011
  307. void * aligned_alloc(size_t, size_t) __malloc_like __alloc_align(1)
  308. __alloc_size(2) __result_use_check;
  309. int at_quick_exit(void (*)(void));
  310. _Noreturn void
  311. quick_exit(int);
  312. #endif /* __ISO_C_VISIBLE >= 2011 */
  313. _END_STD_C
  314. #if __SSP_FORTIFY_LEVEL > 0
  315. #include <ssp/stdlib.h>
  316. #endif
  317. #endif /* _STDLIB_H_ */