msvcrt: Implement _set_doserrno.
[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
11 #include <crtdefs.h>
12
13 #include <pshpack8.h>
14
15 #ifndef NULL
16 #ifdef __cplusplus
17 #define NULL  0
18 #else
19 #define NULL  ((void*)0)
20 #endif
21 #endif
22
23 typedef struct
24 {
25     float f;
26 } _CRT_FLOAT;
27
28 typedef struct
29 {
30     double x;
31 } _CRT_DOUBLE;
32
33 typedef struct
34 {
35     unsigned char ld[10];
36 } _LDOUBLE;
37
38 #define EXIT_SUCCESS        0
39 #define EXIT_FAILURE        -1
40 #define RAND_MAX            0x7FFF
41
42 #ifndef _MAX_PATH
43 #define _MAX_DRIVE          3
44 #define _MAX_FNAME          256
45 #define _MAX_DIR            _MAX_FNAME
46 #define _MAX_EXT            _MAX_FNAME
47 #define _MAX_PATH           260
48 #endif
49
50 /* Make the secure string functions (names end in "_s") truncate their output */
51 #define _TRUNCATE  ((size_t)-1)
52
53 typedef struct _div_t {
54     int quot;
55     int rem;
56 } div_t;
57
58 typedef struct _ldiv_t {
59     __msvcrt_long quot;
60     __msvcrt_long rem;
61 } ldiv_t;
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 #ifdef __i386__
82
83 extern unsigned int* __cdecl __p__osver(void);
84 #define _osver             (*__p__osver())
85 extern unsigned int* __cdecl __p__winver(void);
86 #define _winver            (*__p__winver())
87 extern unsigned int* __cdecl __p__winmajor(void);
88 #define _winmajor          (*__p__winmajor())
89 extern unsigned int* __cdecl __p__winminor(void);
90 #define _winminor          (*__p__winminor())
91 extern int*          __cdecl __p___argc(void);
92 #define __argc             (*__p___argc())
93 extern char***       __cdecl __p___argv(void);
94 #define __argv             (*__p___argv())
95 extern wchar_t***    __cdecl __p___wargv(void);
96 #define __wargv            (*__p___wargv())
97 extern char***       __cdecl __p__environ(void);
98 #define _environ           (*__p__environ())
99 extern wchar_t***    __cdecl __p__wenviron(void);
100 #define _wenviron          (*__p__wenviron())
101 extern unsigned int* __cdecl __p__fmode(void);
102 #define _fmode             (*__p__fmode())
103
104 #else  /* __i386__ */
105
106 extern unsigned int _osver;
107 extern unsigned int _winver;
108 extern unsigned int _winmajor;
109 extern unsigned int _winminor;
110 extern int __argc;
111 extern char **__argv;
112 extern wchar_t **__wargv;
113 extern char **_environ;
114 extern wchar_t **_wenviron;
115 extern unsigned int _fmode;
116
117 #endif  /* __i386__ */
118
119 extern int*           __cdecl ___mb_cur_max_func(void);
120 #define __mb_cur_max        (*___mb_cur_max_func())
121 extern __msvcrt_ulong* __cdecl __doserrno(void);
122 #define _doserrno           (*__doserrno())
123 extern int*           __cdecl _errno(void);
124 #define errno               (*_errno())
125
126 /* FIXME: We need functions to access these:
127  * int _sys_nerr;
128  * char** _sys_errlist;
129  */
130
131 errno_t       __cdecl _get_doserrno(int*);
132 errno_t       __cdecl _get_errno(int*);
133 errno_t       __cdecl _set_doserrno(int);
134 errno_t       __cdecl _set_errno(int);
135
136 typedef int (__cdecl *_onexit_t)(void);
137
138
139 int           __cdecl _atodbl(_CRT_DOUBLE*,char*);
140 int           __cdecl _atoflt(_CRT_FLOAT*,char*);
141 __int64       __cdecl _atoi64(const char*);
142 long double   __cdecl _atold(const char*);
143 int           __cdecl _atoldbl(_LDOUBLE*,char*);
144 void          __cdecl _beep(unsigned int,unsigned int);
145 char*         __cdecl _ecvt(double,int,int*,int*);
146 char*         __cdecl _fcvt(double,int,int*,int*);
147 char*         __cdecl _fullpath(char*,const char*,size_t);
148 char*         __cdecl _gcvt(double,int,char*);
149 char*         __cdecl _i64toa(__int64,char*,int);
150 char*         __cdecl _itoa(int,char*,int);
151 char*         __cdecl _ltoa(__msvcrt_long,char*,int);
152 __msvcrt_ulong __cdecl _lrotl(__msvcrt_ulong,int);
153 __msvcrt_ulong __cdecl _lrotr(__msvcrt_ulong,int);
154 void          __cdecl _makepath(char*,const char*,const char*,const char*,const char*);
155 int           __cdecl _makepath_s(char*,size_t,const char*,const char*,const char*,const char*);
156 size_t        __cdecl _mbstrlen(const char*);
157 _onexit_t     __cdecl _onexit(_onexit_t);
158 int           __cdecl _putenv(const char*);
159 unsigned int  __cdecl _rotl(unsigned int,int);
160 unsigned int  __cdecl _rotr(unsigned int,int);
161 void          __cdecl _searchenv(const char*,const char*,char*);
162 int           __cdecl _set_error_mode(int);
163 void          __cdecl _seterrormode(int);
164 void          __cdecl _sleep(__msvcrt_ulong);
165 void          __cdecl _splitpath(const char*,char*,char*,char*,char*);
166 long double   __cdecl _strtold(const char*,char**);
167 void          __cdecl _swab(char*,char*,int);
168 char*         __cdecl _ui64toa(unsigned __int64,char*,int);
169 errno_t       __cdecl _ui64toa_s(unsigned __int64,char*,size_t,int);
170 char*         __cdecl _ultoa(__msvcrt_ulong,char*,int);
171
172 void          __cdecl _exit(int);
173 void          __cdecl abort(void);
174 int           __cdecl abs(int);
175 int           __cdecl atexit(void (*)(void));
176 double        __cdecl atof(const char*);
177 int           __cdecl atoi(const char*);
178 __msvcrt_long __cdecl atol(const char*);
179 void*         __cdecl calloc(size_t,size_t);
180 #ifndef __i386__
181 div_t  __cdecl div(int,int);
182 ldiv_t __cdecl ldiv(__msvcrt_long,__msvcrt_long);
183 #endif
184 void          __cdecl exit(int);
185 void          __cdecl free(void*);
186 char*         __cdecl getenv(const char*);
187 __msvcrt_long __cdecl labs(__msvcrt_long);
188 void*         __cdecl malloc(size_t);
189 int           __cdecl mblen(const char*,size_t);
190 void          __cdecl perror(const char*);
191 int           __cdecl rand(void);
192 errno_t       __cdecl rand_s(unsigned int*);
193 void*         __cdecl realloc(void*,size_t);
194 void          __cdecl srand(unsigned int);
195 double        __cdecl strtod(const char*,char**);
196 __msvcrt_long __cdecl strtol(const char*,char**,int);
197 __msvcrt_ulong __cdecl strtoul(const char*,char**,int);
198 int           __cdecl system(const char*);
199 void*         __cdecl bsearch(const void*,const void*,size_t,size_t,int (*)(const void*,const void*));
200 void          __cdecl qsort(void*,size_t,size_t,int (*)(const void*,const void*));
201
202 #ifndef _WSTDLIB_DEFINED
203 #define _WSTDLIB_DEFINED
204 wchar_t*      __cdecl _itow(int,wchar_t*,int);
205 wchar_t*      __cdecl _i64tow(__int64,wchar_t*,int);
206 wchar_t*      __cdecl _ltow(__msvcrt_long,wchar_t*,int);
207 wchar_t*      __cdecl _ui64tow(unsigned __int64,wchar_t*,int);
208 wchar_t*      __cdecl _ultow(__msvcrt_ulong,wchar_t*,int);
209 wchar_t*      __cdecl _wfullpath(wchar_t*,const wchar_t*,size_t);
210 wchar_t*      __cdecl _wgetenv(const wchar_t*);
211 void          __cdecl _wmakepath(wchar_t*,const wchar_t*,const wchar_t*,const wchar_t*,const wchar_t*);
212 int           __cdecl _wmakepath_s(wchar_t*,size_t,const wchar_t*,const wchar_t*,const wchar_t*,const wchar_t*);
213 void          __cdecl _wperror(const wchar_t*);
214 int           __cdecl _wputenv(const wchar_t*);
215 void          __cdecl _wsearchenv(const wchar_t*,const wchar_t*,wchar_t*);
216 void          __cdecl _wsplitpath(const wchar_t*,wchar_t*,wchar_t*,wchar_t*,wchar_t*);
217 errno_t       __cdecl _wsplitpath_s(const wchar_t*,wchar_t*,size_t,wchar_t*,size_t,
218                                        wchar_t*,size_t,wchar_t*,size_t);
219 int           __cdecl _wsystem(const wchar_t*);
220 double        __cdecl _wtof(const wchar_t*);
221 int           __cdecl _wtoi(const wchar_t*);
222 __int64       __cdecl _wtoi64(const wchar_t*);
223 __msvcrt_long __cdecl _wtol(const wchar_t*);
224
225 size_t        __cdecl mbstowcs(wchar_t*,const char*,size_t);
226 errno_t       __cdecl mbstowcs_s(size_t*,wchar_t*,size_t,const char*,size_t);
227 int           __cdecl mbtowc(wchar_t*,const char*,size_t);
228 double        __cdecl wcstod(const wchar_t*,wchar_t**);
229 __msvcrt_long __cdecl wcstol(const wchar_t*,wchar_t**,int);
230 size_t        __cdecl wcstombs(char*,const wchar_t*,size_t);
231 errno_t       __cdecl wcstombs_s(size_t*,char*,size_t,const wchar_t*,size_t);
232 __msvcrt_ulong __cdecl wcstoul(const wchar_t*,wchar_t**,int);
233 int           __cdecl wctomb(char*,wchar_t);
234 #endif /* _WSTDLIB_DEFINED */
235
236 typedef void (__cdecl *_invalid_parameter_handler)(const wchar_t*, const wchar_t*, const wchar_t*, unsigned, uintptr_t);
237 _invalid_parameter_handler __cdecl _set_invalid_parameter_handler(_invalid_parameter_handler);
238 _invalid_parameter_handler __cdecl _get_invalid_parameter_handler(void);
239 void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, const wchar_t *file,
240                                 unsigned int line, uintptr_t arg);
241
242 #ifdef __cplusplus
243 }
244 #endif
245
246
247 #define environ _environ
248 #define onexit_t _onexit_t
249
250 static inline char* ecvt(double value, int ndigit, int* decpt, int* sign) { return _ecvt(value, ndigit, decpt, sign); }
251 static inline char* fcvt(double value, int ndigit, int* decpt, int* sign) { return _fcvt(value, ndigit, decpt, sign); }
252 static inline char* gcvt(double value, int ndigit, char* buf) { return _gcvt(value, ndigit, buf); }
253 static inline char* itoa(int value, char* str, int radix) { return _itoa(value, str, radix); }
254 static inline char* ltoa(__msvcrt_long value, char* str, int radix) { return _ltoa(value, str, radix); }
255 static inline _onexit_t onexit(_onexit_t func) { return _onexit(func); }
256 static inline int putenv(const char* str) { return _putenv(str); }
257 static inline void swab(char* src, char* dst, int len) { _swab(src, dst, len); }
258 static inline char* ultoa(__msvcrt_ulong value, char* str, int radix) { return _ultoa(value, str, radix); }
259
260 #ifdef __i386__
261 static inline div_t __wine_msvcrt_div(int num, int denom)
262 {
263     extern unsigned __int64 div(int,int);
264     div_t ret;
265     unsigned __int64 res = div(num,denom);
266     ret.quot = (int)res;
267     ret.rem  = (int)(res >> 32);
268     return ret;
269 }
270 static inline ldiv_t __wine_msvcrt_ldiv(__msvcrt_long num, __msvcrt_long denom)
271 {
272     extern unsigned __int64 ldiv(__msvcrt_long,__msvcrt_long);
273     ldiv_t ret;
274     unsigned __int64 res = ldiv(num,denom);
275     ret.quot = (__msvcrt_long)res;
276     ret.rem  = (__msvcrt_long)(res >> 32);
277     return ret;
278 }
279 #define div(num,denom) __wine_msvcrt_div(num,denom)
280 #define ldiv(num,denom) __wine_msvcrt_ldiv(num,denom)
281 #endif
282
283 #include <poppack.h>
284
285 #endif /* __WINE_STDLIB_H */