widl: Prevent NULL pointer de-refs on "void *" types.
[wine] / include / msvcrt / stdlib.h
CommitLineData
eee695dd
FG
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
5f175508 10#ifndef __WINE_USE_MSVCRT
a45907c4 11#define __WINE_USE_MSVCRT
5f175508 12#endif
eee695dd 13
36d0e5b7
DP
14#ifndef NULL
15#ifdef __cplusplus
16#define NULL 0
17#else
18#define NULL ((void*)0)
19#endif
20#endif
21
03774624
DP
22#ifndef _WCHAR_T_DEFINED
23#define _WCHAR_T_DEFINED
3f5ff2fb 24#ifndef __cplusplus
03774624 25typedef unsigned short wchar_t;
3f5ff2fb
AJ
26#endif
27#endif
eee695dd 28
3f5ff2fb
AJ
29#ifndef _MSC_VER
30# ifndef __int64
31# define __int64 long long
32# endif
33#endif
eee695dd 34
eee695dd
FG
35#define EXIT_SUCCESS 0
36#define EXIT_FAILURE -1
37#define RAND_MAX 0x7FFF
eee695dd
FG
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
03774624 48typedef struct _div_t {
eee695dd
FG
49 int quot;
50 int rem;
03774624 51} div_t;
eee695dd 52
03774624 53typedef struct _ldiv_t {
eee695dd
FG
54 long quot;
55 long rem;
03774624 56} ldiv_t;
eee695dd 57
03774624
DP
58#ifndef _SIZE_T_DEFINED
59typedef unsigned int size_t;
60#define _SIZE_T_DEFINED
3f5ff2fb 61#endif
eee695dd
FG
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
79027d16
FG
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
eee695dd
FG
76
77#ifdef __cplusplus
78extern "C" {
79#endif
80
4056d7ef
EP
81extern unsigned int* __p__osver(void);
82extern unsigned int* __p__winver(void);
83extern unsigned int* __p__winmajor(void);
84extern unsigned int* __p__winminor(void);
eee695dd
FG
85#define _osver (*__p__osver())
86#define _winver (*__p__winver())
87#define _winmajor (*__p__winmajor())
88#define _winminor (*__p__winminor())
89
90extern int* __p___argc(void);
91extern char*** __p___argv(void);
03774624 92extern wchar_t*** __p___wargv(void);
eee695dd 93extern char*** __p__environ(void);
03774624 94extern wchar_t*** __p__wenviron(void);
eee695dd 95extern int* __p___mb_cur_max(void);
03774624 96extern unsigned long* __doserrno(void);
eee695dd
FG
97extern unsigned int* __p__fmode(void);
98/* FIXME: We need functions to access these:
99 * int _sys_nerr;
100 * char** _sys_errlist;
101 */
eee695dd
FG
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)
eee695dd
FG
110
111
03774624
DP
112extern int* _errno(void);
113#define errno (*_errno())
eee695dd
FG
114
115
03774624 116typedef int (*_onexit_t)(void);
eee695dd
FG
117
118
119__int64 _atoi64(const char*);
120long double _atold(const char*);
121void _beep(unsigned int,unsigned int);
122char* _ecvt(double,int,int*,int*);
123char* _fcvt(double,int,int*,int*);
03774624 124char* _fullpath(char*,const char*,size_t);
eee695dd
FG
125char* _gcvt(double,int,char*);
126char* _i64toa(__int64,char*,int);
127char* _itoa(int,char*,int);
128char* _ltoa(long,char*,int);
129unsigned long _lrotl(unsigned long,int);
130unsigned long _lrotr(unsigned long,int);
131void _makepath(char*,const char*,const char*,const char*,const char*);
03774624
DP
132size_t _mbstrlen(const char*);
133_onexit_t _onexit(_onexit_t);
eee695dd
FG
134int _putenv(const char*);
135unsigned int _rotl(unsigned int,int);
136unsigned int _rotr(unsigned int,int);
137void _searchenv(const char*,const char*,char*);
138int _set_error_mode(int);
139void _seterrormode(int);
140void _sleep(unsigned long);
141void _splitpath(const char*,char*,char*,char*,char*);
142long double _strtold(const char*,char**);
03774624 143void _swab(char*,char*,int);
eee695dd
FG
144char* _ui64toa(unsigned __int64,char*,int);
145char* _ultoa(unsigned long,char*,int);
146
03774624 147void _exit(int);
4056d7ef 148void abort(void);
03774624
DP
149int abs(int);
150int atexit(void (*)(void));
151double atof(const char*);
152int atoi(const char*);
153long atol(const char*);
154void* calloc(size_t,size_t);
0b19a6f7 155#ifndef __i386__
03774624
DP
156div_t div(int,int);
157ldiv_t ldiv(long,long);
eee695dd 158#endif
03774624
DP
159void exit(int);
160void free(void*);
161char* getenv(const char*);
162long labs(long);
163void* malloc(size_t);
164int mblen(const char*,size_t);
165void perror(const char*);
166int rand(void);
167void* realloc(void*,size_t);
168void srand(unsigned int);
169double strtod(const char*,char**);
170long strtol(const char*,char**,int);
171unsigned long strtoul(const char*,char**,int);
172int system(const char*);
173void* bsearch(const void*,const void*,size_t,size_t,
3fd4087d 174 int (*)(const void*,const void*));
03774624 175void qsort(void*,size_t,size_t,
3fd4087d 176 int (*)(const void*,const void*));
eee695dd 177
03774624
DP
178#ifndef _WSTDLIB_DEFINED
179#define _WSTDLIB_DEFINED
180wchar_t*_itow(int,wchar_t*,int);
181wchar_t*_i64tow(__int64,wchar_t*,int);
182wchar_t*_ltow(long,wchar_t*,int);
183wchar_t*_ui64tow(unsigned __int64,wchar_t*,int);
184wchar_t*_ultow(unsigned long,wchar_t*,int);
185wchar_t*_wfullpath(wchar_t*,const wchar_t*,size_t);
186wchar_t*_wgetenv(const wchar_t*);
187void _wmakepath(wchar_t*,const wchar_t*,const wchar_t*,const wchar_t*,const wchar_t*);
188void _wperror(const wchar_t*);
189int _wputenv(const wchar_t*);
190void _wsearchenv(const wchar_t*,const wchar_t*,wchar_t*);
191void _wsplitpath(const wchar_t*,wchar_t*,wchar_t*,wchar_t*,wchar_t*);
192int _wsystem(const wchar_t*);
193int _wtoi(const wchar_t*);
194__int64 _wtoi64(const wchar_t*);
195long _wtol(const wchar_t*);
196
197size_t mbstowcs(wchar_t*,const char*,size_t);
198int mbtowc(wchar_t*,const char*,size_t);
199double wcstod(const wchar_t*,wchar_t**);
200long wcstol(const wchar_t*,wchar_t**,int);
201size_t wcstombs(char*,const wchar_t*,size_t);
202unsigned long wcstoul(const wchar_t*,wchar_t**,int);
203int wctomb(char*,wchar_t);
204#endif /* _WSTDLIB_DEFINED */
eee695dd
FG
205
206#ifdef __cplusplus
207}
208#endif
209
210
eee695dd
FG
211#define environ _environ
212#define onexit_t _onexit_t
213
992d1b99
MS
214static inline char* ecvt(double value, int ndigit, int* decpt, int* sign) { return _ecvt(value, ndigit, decpt, sign); }
215static inline char* fcvt(double value, int ndigit, int* decpt, int* sign) { return _fcvt(value, ndigit, decpt, sign); }
216static inline char* gcvt(double value, int ndigit, char* buf) { return _gcvt(value, ndigit, buf); }
217static inline char* itoa(int value, char* str, int radix) { return _itoa(value, str, radix); }
218static inline char* ltoa(long value, char* str, int radix) { return _ltoa(value, str, radix); }
219static inline _onexit_t onexit(_onexit_t func) { return _onexit(func); }
220static inline int putenv(const char* str) { return _putenv(str); }
5f175508 221static inline void swab(char* src, char* dst, int len) { _swab(src, dst, len); }
992d1b99 222static inline char* ultoa(unsigned long value, char* str, int radix) { return _ultoa(value, str, radix); }
0b19a6f7
AJ
223
224#ifdef __i386__
225static 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}
234static 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
eee695dd 247#endif /* __WINE_STDLIB_H */