1 /**
2  * D header file for C99.
3  *
4  * Copyright: Public Domain
5  * License:   Public Domain
6  * Authors:   Sean Kelly
7  * Standards: ISO/IEC 9899:1999 (E)
8  */
9 module tango.stdc.stdlib;
10 
11 private import tango.stdc.stddef;
12 private import tango.stdc.config;
13 private import tango.core.Compiler;
14 
15 extern (C):
16 
17 struct div_t
18 {
19     int quot,
20         rem;
21 }
22 
23 struct ldiv_t
24 {
25     int quot,
26         rem;
27 }
28 
29 struct lldiv_t
30 {
31     long quot,
32          rem;
33 }
34 
35 const EXIT_SUCCESS  = 0;
36 const EXIT_FAILURE  = 1;
37 const RAND_MAX      = 32767;
38 const MB_CUR_MAX    = 1;
39 
40 double  atof(in char* nptr);
41 int     atoi(in char* nptr);
42 c_long  atol(in char* nptr);
43 long    atoll(in char* nptr);
44 
45 double  strtod(in char* nptr, char** endptr);
46 float   strtof(in char* nptr, char** endptr);
47 real    strtold(in char* nptr, char** endptr);
48 c_long  strtol(in char* nptr, char** endptr, int base);
49 long    strtoll(in char* nptr, char** endptr, int base);
50 c_ulong strtoul(in char* nptr, char** endptr, int base);
51 ulong   strtoull(in char* nptr, char** endptr, int base);
52 
53 double  wcstod(in wchar_t* nptr, wchar_t** endptr);
54 float   wcstof(in wchar_t* nptr, wchar_t** endptr);
55 real    wcstold(in wchar_t* nptr, wchar_t** endptr);
56 c_long  wcstol(in wchar_t* nptr, wchar_t** endptr, int base);
57 long    wcstoll(in wchar_t* nptr, wchar_t** endptr, int base);
58 c_ulong wcstoul(in wchar_t* nptr, wchar_t** endptr, int base);
59 ulong   wcstoull(in wchar_t* nptr, wchar_t** endptr, int base);
60 
61 int     rand();
62 void    srand(uint seed);
63 
64 void*   malloc(size_t size);
65 void*   calloc(size_t nmemb, size_t size);
66 void*   realloc(void* ptr, size_t size);
67 void    free(void* ptr);
68 
69 void    abort();
70 void    exit(int status);
71 int     atexit(void function() func);
72 void    _Exit(int status);
73 
74 char*   getenv(in char* name);
75 int     system(in char* string);
76 
77 void*   bsearch(in void* key, in void* base, size_t nmemb, size_t size, int function(in void*, in void*) compar);
78 void    qsort(void* base, size_t nmemb, size_t size, int function(in void*, in void*) compar);
79 
80 int     abs(int j);
81 c_long  labs(c_long j);
82 long    llabs(long j);
83 
84 div_t   div(int numer, int denom);
85 ldiv_t  ldiv(c_long numer, c_long denom);
86 lldiv_t lldiv(long numer, long denom);
87 
88 int     mblen(in char* s, size_t n);
89 int     mbtowc(wchar_t* pwc, in char* s, size_t n);
90 int     wctomb(char*s, wchar_t wc);
91 size_t  mbstowcs(wchar_t* pwcs, in char* s, size_t n);
92 size_t  wcstombs(char* s, in wchar_t* pwcs, size_t n);
93 
94 version( DigitalMars )
95 {
96     void* alloca(size_t size);
97 }
98 else version( LDC )
99 {
100     static if(DMDFE_Version > 2061)
101     {
102         pragma(LDC_alloca)
103             void* alloca(size_t size);
104     }
105     else
106     {
107         pragma(alloca)
108             void* alloca(size_t size);
109     }
110 }
111 else version( GNU )
112 {
113     private import gcc.builtins;
114     alias gcc.builtins.__builtin_alloca alloca;
115 }