Subversion Repositories Kolibri OS

Rev

Rev 6099 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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