2 * Standard library definitions
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.
8 #ifndef __WINE_STDLIB_H
9 #define __WINE_STDLIB_H
10 #ifndef __WINE_USE_MSVCRT
11 #define __WINE_USE_MSVCRT
15 # ifdef USE_MSVCRT_PREFIX
16 # define MSVCRT(x) MSVCRT_##x
26 #define NULL ((void*)0)
30 #ifndef MSVCRT_WCHAR_T_DEFINED
31 #define MSVCRT_WCHAR_T_DEFINED
33 typedef unsigned short MSVCRT(wchar_t);
39 # define __int64 long long
43 #ifndef USE_MSVCRT_PREFIX
44 #define EXIT_SUCCESS 0
45 #define EXIT_FAILURE -1
46 #define RAND_MAX 0x7FFF
48 #define MSVCRT_RAND_MAX 0x7FFF
49 #endif /* USE_MSVCRT_PREFIX */
53 #define _MAX_FNAME 256
54 #define _MAX_DIR _MAX_FNAME
55 #define _MAX_EXT _MAX_FNAME
60 typedef struct MSVCRT(_div_t
) {
65 typedef struct MSVCRT(_ldiv_t
) {
70 #ifndef MSVCRT_SIZE_T_DEFINED
71 typedef unsigned int MSVCRT(size_t);
72 #define MSVCRT_SIZE_T_DEFINED
75 #define __max(a,b) (((a) > (b)) ? (a) : (b))
76 #define __min(a,b) (((a) < (b)) ? (a) : (b))
78 #define max(a,b) (((a) > (b)) ? (a) : (b))
79 #define min(a,b) (((a) < (b)) ? (a) : (b))
82 /* _set_error_mode() constants */
83 #define _OUT_TO_DEFAULT 0
84 #define _OUT_TO_STDERR 1
85 #define _OUT_TO_MSGBOX 2
86 #define _REPORT_ERRMODE 3
93 extern unsigned int* __p__osver();
94 extern unsigned int* __p__winver();
95 extern unsigned int* __p__winmajor();
96 extern unsigned int* __p__winminor();
97 #define _osver (*__p__osver())
98 #define _winver (*__p__winver())
99 #define _winmajor (*__p__winmajor())
100 #define _winminor (*__p__winminor())
102 extern int* __p___argc(void);
103 extern char*** __p___argv(void);
104 extern MSVCRT(wchar_t)*** __p___wargv(void);
105 extern char*** __p__environ(void);
106 extern MSVCRT(wchar_t)*** __p__wenviron(void);
107 extern int* __p___mb_cur_max(void);
108 extern unsigned long* __doserrno(void);
109 extern unsigned int* __p__fmode(void);
110 /* FIXME: We need functions to access these:
112 * char** _sys_errlist;
114 #ifndef USE_MSVCRT_PREFIX
115 #define __argc (*__p___argc())
116 #define __argv (*__p___argv())
117 #define __wargv (*__p___wargv())
118 #define _environ (*__p__environ())
119 #define _wenviron (*__p__wenviron())
120 #define __mb_cur_max (*__p___mb_cur_max())
121 #define _doserrno (*__doserrno())
122 #define _fmode (*_fmode)
123 #endif /* USE_MSVCRT_PREFIX */
126 extern int* MSVCRT(_errno
)(void);
127 #ifndef USE_MSVCRT_PREFIX
128 # define errno (*_errno())
130 # define MSVCRT_errno (*MSVCRT__errno())
134 typedef int (*_onexit_t
)(void);
137 __int64
_atoi64(const char*);
138 long double _atold(const char*);
139 void _beep(unsigned int,unsigned int);
140 char* _ecvt(double,int,int*,int*);
141 char* _fcvt(double,int,int*,int*);
142 char* _fullpath(char*,const char*,MSVCRT(size_t));
143 char* _gcvt(double,int,char*);
144 char* _i64toa(__int64
,char*,int);
145 char* _itoa(int,char*,int);
146 char* _ltoa(long,char*,int);
147 unsigned long _lrotl(unsigned long,int);
148 unsigned long _lrotr(unsigned long,int);
149 void _makepath(char*,const char*,const char*,const char*,const char*);
150 MSVCRT(size_t) _mbstrlen(const char*);
151 _onexit_t
_onexit(_onexit_t
);
152 int _putenv(const char*);
153 unsigned int _rotl(unsigned int,int);
154 unsigned int _rotr(unsigned int,int);
155 void _searchenv(const char*,const char*,char*);
156 int _set_error_mode(int);
157 void _seterrormode(int);
158 void _sleep(unsigned long);
159 void _splitpath(const char*,char*,char*,char*,char*);
160 long double _strtold(const char*,char**);
161 void _swab(char*,char*,int);
162 char* _ui64toa(unsigned __int64
,char*,int);
163 char* _ultoa(unsigned long,char*,int);
165 void MSVCRT(_exit
)(int);
166 void MSVCRT(abort
)();
167 int MSVCRT(abs
)(int);
168 int MSVCRT(atexit
)(void (*)(void));
169 double MSVCRT(atof
)(const char*);
170 int MSVCRT(atoi
)(const char*);
171 long MSVCRT(atol
)(const char*);
172 void* MSVCRT(calloc
)(MSVCRT(size_t),MSVCRT(size_t));
174 MSVCRT(div_t) MSVCRT(div
)(int,int);
175 MSVCRT(ldiv_t) MSVCRT(ldiv
)(long,long);
177 void MSVCRT(exit
)(int);
178 void MSVCRT(free
)(void*);
179 char* MSVCRT(getenv
)(const char*);
180 long MSVCRT(labs
)(long);
181 void* MSVCRT(malloc
)(MSVCRT(size_t));
182 int MSVCRT(mblen
)(const char*,MSVCRT(size_t));
183 void MSVCRT(perror
)(const char*);
184 int MSVCRT(rand
)(void);
185 void* MSVCRT(realloc
)(void*,MSVCRT(size_t));
186 void MSVCRT(srand
)(unsigned int);
187 double MSVCRT(strtod
)(const char*,char**);
188 long MSVCRT(strtol
)(const char*,char**,int);
189 unsigned long MSVCRT(strtoul
)(const char*,char**,int);
190 int MSVCRT(system
)(const char*);
191 void* MSVCRT(bsearch
)(const void*,const void*,MSVCRT(size_t),MSVCRT(size_t),
192 int (*)(const void*,const void*));
193 void MSVCRT(qsort
)(void*,MSVCRT(size_t),MSVCRT(size_t),
194 int (*)(const void*,const void*));
196 #ifndef MSVCRT_WSTDLIB_DEFINED
197 #define MSVCRT_WSTDLIB_DEFINED
198 MSVCRT(wchar_t)*_itow(int,MSVCRT(wchar_t)*,int);
199 MSVCRT(wchar_t)*_i64tow(__int64
,MSVCRT(wchar_t)*,int);
200 MSVCRT(wchar_t)*_ltow(long,MSVCRT(wchar_t)*,int);
201 MSVCRT(wchar_t)*_ui64tow(unsigned __int64
,MSVCRT(wchar_t)*,int);
202 MSVCRT(wchar_t)*_ultow(unsigned long,MSVCRT(wchar_t)*,int);
203 MSVCRT(wchar_t)*_wfullpath(MSVCRT(wchar_t)*,const MSVCRT(wchar_t)*,MSVCRT(size_t));
204 MSVCRT(wchar_t)*_wgetenv(const MSVCRT(wchar_t)*);
205 void _wmakepath(MSVCRT(wchar_t)*,const MSVCRT(wchar_t)*,const MSVCRT(wchar_t)*,const MSVCRT(wchar_t)*,const MSVCRT(wchar_t)*);
206 void _wperror(const MSVCRT(wchar_t)*);
207 int _wputenv(const MSVCRT(wchar_t)*);
208 void _wsearchenv(const MSVCRT(wchar_t)*,const MSVCRT(wchar_t)*,MSVCRT(wchar_t)*);
209 void _wsplitpath(const MSVCRT(wchar_t)*,MSVCRT(wchar_t)*,MSVCRT(wchar_t)*,MSVCRT(wchar_t)*,MSVCRT(wchar_t)*);
210 int _wsystem(const MSVCRT(wchar_t)*);
211 int _wtoi(const MSVCRT(wchar_t)*);
212 __int64
_wtoi64(const MSVCRT(wchar_t)*);
213 long _wtol(const MSVCRT(wchar_t)*);
215 MSVCRT(size_t) MSVCRT(mbstowcs
)(MSVCRT(wchar_t)*,const char*,MSVCRT(size_t));
216 int MSVCRT(mbtowc
)(MSVCRT(wchar_t)*,const char*,MSVCRT(size_t));
217 double MSVCRT(wcstod
)(const MSVCRT(wchar_t)*,MSVCRT(wchar_t)**);
218 long MSVCRT(wcstol
)(const MSVCRT(wchar_t)*,MSVCRT(wchar_t)**,int);
219 MSVCRT(size_t) MSVCRT(wcstombs
)(char*,const MSVCRT(wchar_t)*,MSVCRT(size_t));
220 unsigned long MSVCRT(wcstoul
)(const MSVCRT(wchar_t)*,MSVCRT(wchar_t)**,int);
221 int MSVCRT(wctomb
)(char*,MSVCRT(wchar_t));
222 #endif /* MSVCRT_WSTDLIB_DEFINED */
229 #ifndef USE_MSVCRT_PREFIX
230 #define environ _environ
231 #define onexit_t _onexit_t
233 static inline char* ecvt(double value
, int ndigit
, int* decpt
, int* sign
) { return _ecvt(value
, ndigit
, decpt
, sign
); }
234 static inline char* fcvt(double value
, int ndigit
, int* decpt
, int* sign
) { return _fcvt(value
, ndigit
, decpt
, sign
); }
235 static inline char* gcvt(double value
, int ndigit
, char* buf
) { return _gcvt(value
, ndigit
, buf
); }
236 static inline char* itoa(int value
, char* str
, int radix
) { return _itoa(value
, str
, radix
); }
237 static inline char* ltoa(long value
, char* str
, int radix
) { return _ltoa(value
, str
, radix
); }
238 static inline _onexit_t
onexit(_onexit_t func
) { return _onexit(func
); }
239 static inline int putenv(const char* str
) { return _putenv(str
); }
240 static inline void swab(char* src
, char* dst
, int len
) { _swab(src
, dst
, len
); }
241 static inline char* ultoa(unsigned long value
, char* str
, int radix
) { return _ultoa(value
, str
, radix
); }
244 static inline div_t __wine_msvcrt_div(int num
, int denom
)
246 extern unsigned __int64
div(int,int);
248 unsigned __int64 res
= div(num
,denom
);
250 ret
.rem
= (int)(res
>> 32);
253 static inline ldiv_t __wine_msvcrt_ldiv(long num
, long denom
)
255 extern unsigned __int64
ldiv(long,long);
257 unsigned __int64 res
= ldiv(num
,denom
);
258 ret
.quot
= (long)res
;
259 ret
.rem
= (long)(res
>> 32);
262 #define div(num,denom) __wine_msvcrt_div(num,denom)
263 #define ldiv(num,denom) __wine_msvcrt_ldiv(num,denom)
266 #endif /* USE_MSVCRT_PREFIX */
268 #endif /* __WINE_STDLIB_H */