stdlib.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. _BEGIN_STD_C
  24. typedef struct
  25. {
  26. int quot; /* quotient */
  27. int rem; /* remainder */
  28. } div_t;
  29. typedef struct
  30. {
  31. long quot; /* quotient */
  32. long rem; /* remainder */
  33. } ldiv_t;
  34. #if !defined(__STRICT_ANSI__) || \
  35. (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
  36. (defined(__cplusplus) && __cplusplus >= 201103L)
  37. typedef struct
  38. {
  39. long long int quot; /* quotient */
  40. long long int rem; /* remainder */
  41. } lldiv_t;
  42. #endif
  43. #ifndef __compar_fn_t_defined
  44. #define __compar_fn_t_defined
  45. typedef int (*__compar_fn_t) (const _PTR, const _PTR);
  46. #endif
  47. #ifndef NULL
  48. #define NULL 0
  49. #endif
  50. #define EXIT_FAILURE 1
  51. #define EXIT_SUCCESS 0
  52. #define RAND_MAX __RAND_MAX
  53. int _EXFUN(__locale_mb_cur_max,(_VOID));
  54. #define MB_CUR_MAX __locale_mb_cur_max()
  55. _VOID _EXFUN(abort,(_VOID) _ATTRIBUTE ((__noreturn__)));
  56. int _EXFUN(abs,(int));
  57. int _EXFUN(atexit,(_VOID (*__func)(_VOID)));
  58. double _EXFUN(atof,(const char *__nptr));
  59. #ifndef __STRICT_ANSI__
  60. float _EXFUN(atoff,(const char *__nptr));
  61. #endif
  62. int _EXFUN(atoi,(const char *__nptr));
  63. int _EXFUN(_atoi_r,(struct _reent *, const char *__nptr));
  64. long _EXFUN(atol,(const char *__nptr));
  65. long _EXFUN(_atol_r,(struct _reent *, const char *__nptr));
  66. _PTR _EXFUN(bsearch,(const _PTR __key,
  67. const _PTR __base,
  68. size_t __nmemb,
  69. size_t __size,
  70. __compar_fn_t _compar));
  71. _PTR _EXFUN_NOTHROW(calloc,(size_t __nmemb, size_t __size));
  72. div_t _EXFUN(div,(int __numer, int __denom));
  73. _VOID _EXFUN(exit,(int __status) _ATTRIBUTE ((__noreturn__)));
  74. _VOID _EXFUN_NOTHROW(free,(_PTR));
  75. char * _EXFUN(getenv,(const char *__string));
  76. char * _EXFUN(_getenv_r,(struct _reent *, const char *__string));
  77. char * _EXFUN(_findenv,(_CONST char *, int *));
  78. char * _EXFUN(_findenv_r,(struct _reent *, _CONST char *, int *));
  79. #ifndef __STRICT_ANSI__
  80. extern char *suboptarg; /* getsubopt(3) external variable */
  81. int _EXFUN(getsubopt,(char **, char * const *, char **));
  82. #endif
  83. long _EXFUN(labs,(long));
  84. ldiv_t _EXFUN(ldiv,(long __numer, long __denom));
  85. _PTR _EXFUN_NOTHROW(malloc,(size_t __size));
  86. int _EXFUN(mblen,(const char *, size_t));
  87. int _EXFUN(_mblen_r,(struct _reent *, const char *, size_t, _mbstate_t *));
  88. int _EXFUN(mbtowc,(wchar_t *__restrict, const char *__restrict, size_t));
  89. int _EXFUN(_mbtowc_r,(struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *));
  90. int _EXFUN(wctomb,(char *, wchar_t));
  91. int _EXFUN(_wctomb_r,(struct _reent *, char *, wchar_t, _mbstate_t *));
  92. size_t _EXFUN(mbstowcs,(wchar_t *__restrict, const char *__restrict, size_t));
  93. size_t _EXFUN(_mbstowcs_r,(struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *));
  94. size_t _EXFUN(wcstombs,(char *__restrict, const wchar_t *__restrict, size_t));
  95. size_t _EXFUN(_wcstombs_r,(struct _reent *, char *__restrict, const wchar_t *__restrict, size_t, _mbstate_t *));
  96. #ifndef __STRICT_ANSI__
  97. #ifndef _REENT_ONLY
  98. char * _EXFUN(mkdtemp,(char *));
  99. int _EXFUN(mkostemp,(char *, int));
  100. int _EXFUN(mkostemps,(char *, int, int));
  101. int _EXFUN(mkstemp,(char *));
  102. int _EXFUN(mkstemps,(char *, int));
  103. #if (__GNUC__ < 4) || defined(__XTENSA__)
  104. char * _EXFUN(mktemp,(char *));
  105. #else
  106. char * _EXFUN(mktemp,(char *) _ATTRIBUTE ((__warning__ ("the use of `mktemp' is dangerous; use `mkstemp' instead"))));
  107. #endif
  108. #endif
  109. char * _EXFUN(_mkdtemp_r, (struct _reent *, char *));
  110. int _EXFUN(_mkostemp_r, (struct _reent *, char *, int));
  111. int _EXFUN(_mkostemps_r, (struct _reent *, char *, int, int));
  112. int _EXFUN(_mkstemp_r, (struct _reent *, char *));
  113. int _EXFUN(_mkstemps_r, (struct _reent *, char *, int));
  114. #if (__GNUC__ < 4) || defined(__XTENSA__)
  115. char * _EXFUN(_mktemp_r, (struct _reent *, char *));
  116. #else
  117. char * _EXFUN(_mktemp_r, (struct _reent *, char *) _ATTRIBUTE ((__warning__ ("the use of `mktemp' is dangerous; use `mkstemp' instead"))));
  118. #endif
  119. #endif
  120. _VOID _EXFUN(qsort,(_PTR __base, size_t __nmemb, size_t __size, __compar_fn_t _compar));
  121. int _EXFUN(rand,(_VOID));
  122. _PTR _EXFUN_NOTHROW(realloc,(_PTR __r, size_t __size));
  123. #ifndef __STRICT_ANSI__
  124. _PTR _EXFUN(reallocf,(_PTR __r, size_t __size));
  125. char * _EXFUN(realpath, (const char *__restrict path, char *__restrict resolved_path));
  126. #endif
  127. _VOID _EXFUN(srand,(unsigned __seed));
  128. double _EXFUN(strtod,(const char *__restrict __n, char **__restrict __end_PTR));
  129. double _EXFUN(_strtod_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR));
  130. #if !defined(__STRICT_ANSI__) || \
  131. (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
  132. (defined(__cplusplus) && __cplusplus >= 201103L)
  133. float _EXFUN(strtof,(const char *__restrict __n, char **__restrict __end_PTR));
  134. #endif
  135. #ifndef __STRICT_ANSI__
  136. /* the following strtodf interface is deprecated...use strtof instead */
  137. # ifndef strtodf
  138. # define strtodf strtof
  139. # endif
  140. #endif
  141. long _EXFUN(strtol,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
  142. long _EXFUN(_strtol_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR, int __base));
  143. unsigned long _EXFUN(strtoul,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
  144. unsigned long _EXFUN(_strtoul_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR, int __base));
  145. int _EXFUN(system,(const char *__string));
  146. #ifndef __STRICT_ANSI__
  147. long _EXFUN(a64l,(const char *__input));
  148. char * _EXFUN(l64a,(long __input));
  149. char * _EXFUN(_l64a_r,(struct _reent *,long __input));
  150. int _EXFUN(on_exit,(_VOID (*__func)(int, _PTR),_PTR __arg));
  151. #endif /* ! __STRICT_ANSI__ */
  152. #if !defined(__STRICT_ANSI__) || \
  153. (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
  154. (defined(__cplusplus) && __cplusplus >= 201103L)
  155. _VOID _EXFUN(_Exit,(int __status) _ATTRIBUTE ((__noreturn__)));
  156. #endif
  157. #ifndef __STRICT_ANSI__
  158. int _EXFUN(putenv,(char *__string));
  159. int _EXFUN(_putenv_r,(struct _reent *, char *__string));
  160. _PTR _EXFUN(_reallocf_r,(struct _reent *, _PTR, size_t));
  161. int _EXFUN(setenv,(const char *__string, const char *__value, int __overwrite));
  162. int _EXFUN(_setenv_r,(struct _reent *, const char *__string, const char *__value, int __overwrite));
  163. char * _EXFUN(gcvt,(double,int,char *));
  164. char * _EXFUN(gcvtf,(float,int,char *));
  165. char * _EXFUN(fcvt,(double,int,int *,int *));
  166. char * _EXFUN(fcvtf,(float,int,int *,int *));
  167. char * _EXFUN(ecvt,(double,int,int *,int *));
  168. char * _EXFUN(ecvtbuf,(double, int, int*, int*, char *));
  169. char * _EXFUN(fcvtbuf,(double, int, int*, int*, char *));
  170. char * _EXFUN(ecvtf,(float,int,int *,int *));
  171. char * _EXFUN(dtoa,(double, int, int, int *, int*, char**));
  172. #endif
  173. char * _EXFUN(__itoa,(int, char *, int));
  174. char * _EXFUN(__utoa,(unsigned, char *, int));
  175. #ifndef __STRICT_ANSI__
  176. char * _EXFUN(itoa,(int, char *, int));
  177. char * _EXFUN(utoa,(unsigned, char *, int));
  178. int _EXFUN(rand_r,(unsigned *__seed));
  179. double _EXFUN(drand48,(_VOID));
  180. double _EXFUN(_drand48_r,(struct _reent *));
  181. double _EXFUN(erand48,(unsigned short [3]));
  182. double _EXFUN(_erand48_r,(struct _reent *, unsigned short [3]));
  183. long _EXFUN(jrand48,(unsigned short [3]));
  184. long _EXFUN(_jrand48_r,(struct _reent *, unsigned short [3]));
  185. _VOID _EXFUN(lcong48,(unsigned short [7]));
  186. _VOID _EXFUN(_lcong48_r,(struct _reent *, unsigned short [7]));
  187. long _EXFUN(lrand48,(_VOID));
  188. long _EXFUN(_lrand48_r,(struct _reent *));
  189. long _EXFUN(mrand48,(_VOID));
  190. long _EXFUN(_mrand48_r,(struct _reent *));
  191. long _EXFUN(nrand48,(unsigned short [3]));
  192. long _EXFUN(_nrand48_r,(struct _reent *, unsigned short [3]));
  193. unsigned short *
  194. _EXFUN(seed48,(unsigned short [3]));
  195. unsigned short *
  196. _EXFUN(_seed48_r,(struct _reent *, unsigned short [3]));
  197. _VOID _EXFUN(srand48,(long));
  198. _VOID _EXFUN(_srand48_r,(struct _reent *, long));
  199. #endif /* ! __STRICT_ANSI__ */
  200. #if !defined(__STRICT_ANSI__) || \
  201. (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
  202. (defined(__cplusplus) && __cplusplus >= 201103L)
  203. long long _EXFUN(atoll,(const char *__nptr));
  204. #endif
  205. #ifndef __STRICT_ANSI__
  206. long long _EXFUN(_atoll_r,(struct _reent *, const char *__nptr));
  207. #endif /* ! __STRICT_ANSI__ */
  208. #if !defined(__STRICT_ANSI__) || \
  209. (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
  210. (defined(__cplusplus) && __cplusplus >= 201103L)
  211. long long _EXFUN(llabs,(long long));
  212. lldiv_t _EXFUN(lldiv,(long long __numer, long long __denom));
  213. long long _EXFUN(strtoll,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
  214. #endif
  215. #ifndef __STRICT_ANSI__
  216. long long _EXFUN(_strtoll_r,(struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base));
  217. #endif /* ! __STRICT_ANSI__ */
  218. #if !defined(__STRICT_ANSI__) || \
  219. (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
  220. (defined(__cplusplus) && __cplusplus >= 201103L)
  221. unsigned long long _EXFUN(strtoull,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
  222. #endif
  223. #ifndef __STRICT_ANSI__
  224. unsigned long long _EXFUN(_strtoull_r,(struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base));
  225. #ifndef __CYGWIN__
  226. _VOID _EXFUN(cfree,(_PTR));
  227. int _EXFUN(unsetenv,(const char *__string));
  228. int _EXFUN(_unsetenv_r,(struct _reent *, const char *__string));
  229. #endif
  230. #ifdef __rtems__
  231. int _EXFUN(posix_memalign,(void **, size_t, size_t));
  232. #endif
  233. #endif /* ! __STRICT_ANSI__ */
  234. char * _EXFUN(_dtoa_r,(struct _reent *, double, int, int, int *, int*, char**));
  235. #ifndef __CYGWIN__
  236. _PTR _EXFUN_NOTHROW(_malloc_r,(struct _reent *, size_t));
  237. _PTR _EXFUN_NOTHROW(_calloc_r,(struct _reent *, size_t, size_t));
  238. _VOID _EXFUN_NOTHROW(_free_r,(struct _reent *, _PTR));
  239. _PTR _EXFUN_NOTHROW(_realloc_r,(struct _reent *, _PTR, size_t));
  240. _VOID _EXFUN(_mstats_r,(struct _reent *, char *));
  241. #endif
  242. int _EXFUN(_system_r,(struct _reent *, const char *));
  243. _VOID _EXFUN(__eprintf,(const char *, const char *, unsigned int, const char *));
  244. /* There are two common qsort_r variants. If you request
  245. _BSD_SOURCE, you get the BSD version; otherwise you get the GNU
  246. version. We want that #undef qsort_r will still let you
  247. invoke the underlying function, but that requires gcc support. */
  248. #ifdef _BSD_SOURCE
  249. # ifdef __GNUC__
  250. _VOID _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, _PTR __thunk, int (*_compar)(_PTR, const _PTR, const _PTR)))
  251. __asm__ (__ASMNAME ("__bsd_qsort_r"));
  252. # else
  253. _VOID _EXFUN(__bsd_qsort_r,(_PTR __base, size_t __nmemb, size_t __size, _PTR __thunk, int (*_compar)(_PTR, const _PTR, const _PTR)));
  254. # define qsort_r __bsd_qsort_r
  255. # endif
  256. #elif __GNU_VISIBLE
  257. _VOID _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, int (*_compar)(const _PTR, const _PTR, _PTR), _PTR __thunk));
  258. #endif
  259. /* On platforms where long double equals double. */
  260. #ifdef _HAVE_LONG_DOUBLE
  261. #if !defined(__STRICT_ANSI__) || \
  262. (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
  263. (defined(__cplusplus) && __cplusplus >= 201103L)
  264. extern long double strtold (const char *__restrict, char **__restrict);
  265. #endif
  266. #endif /* _HAVE_LONG_DOUBLE */
  267. _END_STD_C
  268. #endif /* _STDLIB_H_ */