Add some missing interfaces.
[wine] / include / msvcrt / stdlib.h
1 /*
2  * Standard library definitions
3  *
4  * Derived from the mingw header written by Colin Peters.
5  * Modified for Wine use by Jon Griffiths and Francois Gouget.
6  * This file is in the public domain.
7  */
8 #ifndef __WINE_STDLIB_H
9 #define __WINE_STDLIB_H
10 #ifndef __WINE_USE_MSVCRT
11 #define __WINE_USE_MSVCRT
12 #endif
13
14 #ifndef NULL
15 #ifdef __cplusplus
16 #define NULL  0
17 #else
18 #define NULL  ((void*)0)
19 #endif
20 #endif
21
22 #ifndef _WCHAR_T_DEFINED
23 #define _WCHAR_T_DEFINED
24 #ifndef __cplusplus
25 typedef unsigned short wchar_t;
26 #endif
27 #endif
28
29 #ifndef _MSC_VER
30 # ifndef __int64
31 #  define __int64 long long
32 # endif
33 #endif
34
35 #define EXIT_SUCCESS        0
36 #define EXIT_FAILURE        -1
37 #define RAND_MAX            0x7FFF
38
39 #ifndef _MAX_PATH
40 #define _MAX_DRIVE          3
41 #define _MAX_FNAME          256
42 #define _MAX_DIR            _MAX_FNAME
43 #define _MAX_EXT            _MAX_FNAME
44 #define _MAX_PATH           260
45 #endif
46
47
48 typedef struct _div_t {
49     int quot;
50     int rem;
51 } div_t;
52
53 typedef struct _ldiv_t {
54     long quot;
55     long rem;
56 } ldiv_t;
57
58 #ifndef _SIZE_T_DEFINED
59 typedef unsigned int size_t;
60 #define _SIZE_T_DEFINED
61 #endif
62
63 #define __max(a,b) (((a) > (b)) ? (a) : (b))
64 #define __min(a,b) (((a) < (b)) ? (a) : (b))
65 #ifndef __cplusplus
66 #define max(a,b)   (((a) > (b)) ? (a) : (b))
67 #define min(a,b)   (((a) < (b)) ? (a) : (b))
68 #endif
69
70 /* _set_error_mode() constants */
71 #define _OUT_TO_DEFAULT      0
72 #define _OUT_TO_STDERR       1
73 #define _OUT_TO_MSGBOX       2
74 #define _REPORT_ERRMODE      3
75
76
77 #ifdef __cplusplus
78 extern "C" {
79 #endif
80
81 extern unsigned int*         __p__osver(void);
82 extern unsigned int*         __p__winver(void);
83 extern unsigned int*         __p__winmajor(void);
84 extern unsigned int*         __p__winminor(void);
85 #define _osver             (*__p__osver())
86 #define _winver            (*__p__winver())
87 #define _winmajor          (*__p__winmajor())
88 #define _winminor          (*__p__winminor())
89
90 extern int*                  __p___argc(void);
91 extern char***               __p___argv(void);
92 extern wchar_t***    __p___wargv(void);
93 extern char***               __p__environ(void);
94 extern wchar_t***    __p__wenviron(void);
95 extern int*                  __p___mb_cur_max(void);
96 extern unsigned long*        __doserrno(void);
97 extern unsigned int*         __p__fmode(void);
98 /* FIXME: We need functions to access these:
99  * int _sys_nerr;
100  * char** _sys_errlist;
101  */
102 #define __argc             (*__p___argc())
103 #define __argv             (*__p___argv())
104 #define __wargv            (*__p___wargv())
105 #define _environ           (*__p__environ())
106 #define _wenviron          (*__p__wenviron())
107 #define __mb_cur_max       (*__p___mb_cur_max())
108 #define _doserrno          (*__doserrno())
109 #define _fmode             (*_fmode)
110
111
112 extern int*           _errno(void);
113 #define errno        (*_errno())
114
115
116 typedef int (*_onexit_t)(void);
117
118
119 __int64     _atoi64(const char*);
120 long double _atold(const char*);
121 void        _beep(unsigned int,unsigned int);
122 char*       _ecvt(double,int,int*,int*);
123 char*       _fcvt(double,int,int*,int*);
124 char*       _fullpath(char*,const char*,size_t);
125 char*       _gcvt(double,int,char*);
126 char*       _i64toa(__int64,char*,int);
127 char*       _itoa(int,char*,int);
128 char*       _ltoa(long,char*,int);
129 unsigned long _lrotl(unsigned long,int);
130 unsigned long _lrotr(unsigned long,int);
131 void        _makepath(char*,const char*,const char*,const char*,const char*);
132 size_t _mbstrlen(const char*);
133 _onexit_t _onexit(_onexit_t);
134 int         _putenv(const char*);
135 unsigned int _rotl(unsigned int,int);
136 unsigned int _rotr(unsigned int,int);
137 void        _searchenv(const char*,const char*,char*);
138 int         _set_error_mode(int);
139 void        _seterrormode(int);
140 void        _sleep(unsigned long);
141 void        _splitpath(const char*,char*,char*,char*,char*);
142 long double _strtold(const char*,char**);
143 void        _swab(char*,char*,int);
144 char*       _ui64toa(unsigned __int64,char*,int);
145 char*       _ultoa(unsigned long,char*,int);
146
147 void        _exit(int);
148 void        abort(void);
149 int         abs(int);
150 int         atexit(void (*)(void));
151 double      atof(const char*);
152 int         atoi(const char*);
153 long        atol(const char*);
154 void*       calloc(size_t,size_t);
155 #ifndef __i386__
156 div_t div(int,int);
157 ldiv_t ldiv(long,long);
158 #endif
159 void        exit(int);
160 void        free(void*);
161 char*       getenv(const char*);
162 long        labs(long);
163 void*       malloc(size_t);
164 int         mblen(const char*,size_t);
165 void        perror(const char*);
166 int         rand(void);
167 void*       realloc(void*,size_t);
168 void        srand(unsigned int);
169 double      strtod(const char*,char**);
170 long        strtol(const char*,char**,int);
171 unsigned long strtoul(const char*,char**,int);
172 int         system(const char*);
173 void*       bsearch(const void*,const void*,size_t,size_t,
174                             int (*)(const void*,const void*));
175 void        qsort(void*,size_t,size_t,
176                           int (*)(const void*,const void*));
177
178 #ifndef _WSTDLIB_DEFINED
179 #define _WSTDLIB_DEFINED
180 wchar_t*_itow(int,wchar_t*,int);
181 wchar_t*_i64tow(__int64,wchar_t*,int);
182 wchar_t*_ltow(long,wchar_t*,int);
183 wchar_t*_ui64tow(unsigned __int64,wchar_t*,int);
184 wchar_t*_ultow(unsigned long,wchar_t*,int);
185 wchar_t*_wfullpath(wchar_t*,const wchar_t*,size_t);
186 wchar_t*_wgetenv(const wchar_t*);
187 void            _wmakepath(wchar_t*,const wchar_t*,const wchar_t*,const wchar_t*,const wchar_t*);
188 void            _wperror(const wchar_t*);
189 int             _wputenv(const wchar_t*);
190 void            _wsearchenv(const wchar_t*,const wchar_t*,wchar_t*);
191 void            _wsplitpath(const wchar_t*,wchar_t*,wchar_t*,wchar_t*,wchar_t*);
192 int             _wsystem(const wchar_t*);
193 int             _wtoi(const wchar_t*);
194 __int64         _wtoi64(const wchar_t*);
195 long            _wtol(const wchar_t*);
196
197 size_t mbstowcs(wchar_t*,const char*,size_t);
198 int            mbtowc(wchar_t*,const char*,size_t);
199 double         wcstod(const wchar_t*,wchar_t**);
200 long           wcstol(const wchar_t*,wchar_t**,int);
201 size_t wcstombs(char*,const wchar_t*,size_t);
202 unsigned long  wcstoul(const wchar_t*,wchar_t**,int);
203 int            wctomb(char*,wchar_t);
204 #endif /* _WSTDLIB_DEFINED */
205
206 #ifdef __cplusplus
207 }
208 #endif
209
210
211 #define environ _environ
212 #define onexit_t _onexit_t
213
214 static inline char* ecvt(double value, int ndigit, int* decpt, int* sign) { return _ecvt(value, ndigit, decpt, sign); }
215 static inline char* fcvt(double value, int ndigit, int* decpt, int* sign) { return _fcvt(value, ndigit, decpt, sign); }
216 static inline char* gcvt(double value, int ndigit, char* buf) { return _gcvt(value, ndigit, buf); }
217 static inline char* itoa(int value, char* str, int radix) { return _itoa(value, str, radix); }
218 static inline char* ltoa(long value, char* str, int radix) { return _ltoa(value, str, radix); }
219 static inline _onexit_t onexit(_onexit_t func) { return _onexit(func); }
220 static inline int putenv(const char* str) { return _putenv(str); }
221 static inline void swab(char* src, char* dst, int len) { _swab(src, dst, len); }
222 static inline char* ultoa(unsigned long value, char* str, int radix) { return _ultoa(value, str, radix); }
223
224 #ifdef __i386__
225 static inline div_t __wine_msvcrt_div(int num, int denom)
226 {
227     extern unsigned __int64 div(int,int);
228     div_t ret;
229     unsigned __int64 res = div(num,denom);
230     ret.quot = (int)res;
231     ret.rem  = (int)(res >> 32);
232     return ret;
233 }
234 static inline ldiv_t __wine_msvcrt_ldiv(long num, long denom)
235 {
236     extern unsigned __int64 ldiv(long,long);
237     ldiv_t ret;
238     unsigned __int64 res = ldiv(num,denom);
239     ret.quot = (long)res;
240     ret.rem  = (long)(res >> 32);
241     return ret;
242 }
243 #define div(num,denom) __wine_msvcrt_div(num,denom)
244 #define ldiv(num,denom) __wine_msvcrt_ldiv(num,denom)
245 #endif
246
247 #endif /* __WINE_STDLIB_H */