Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 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 |
Alexandre Julliard | 33fa6c2 | 2008-12-11 22:37:34 +0100 | [diff] [blame] | 10 | |
| 11 | #include <crtdefs.h> |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 12 | |
Dmitry Timoshkov | 2af96fe | 2007-02-20 16:35:41 +0800 | [diff] [blame] | 13 | #include <pshpack8.h> |
| 14 | |
Dimitrie O. Paun | 36d0e5b | 2003-01-03 03:07:06 +0000 | [diff] [blame] | 15 | #ifndef NULL |
| 16 | #ifdef __cplusplus |
| 17 | #define NULL 0 |
| 18 | #else |
| 19 | #define NULL ((void*)0) |
| 20 | #endif |
| 21 | #endif |
| 22 | |
Francois Gouget | dd3e2be | 2007-08-30 16:15:47 +0200 | [diff] [blame] | 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 | |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 38 | #define EXIT_SUCCESS 0 |
| 39 | #define EXIT_FAILURE -1 |
| 40 | #define RAND_MAX 0x7FFF |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 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 | |
Dimitrie O. Paun | 0377462 | 2004-06-25 01:19:15 +0000 | [diff] [blame] | 51 | typedef struct _div_t { |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 52 | int quot; |
| 53 | int rem; |
Dimitrie O. Paun | 0377462 | 2004-06-25 01:19:15 +0000 | [diff] [blame] | 54 | } div_t; |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 55 | |
Dimitrie O. Paun | 0377462 | 2004-06-25 01:19:15 +0000 | [diff] [blame] | 56 | typedef struct _ldiv_t { |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 57 | long quot; |
| 58 | long rem; |
Dimitrie O. Paun | 0377462 | 2004-06-25 01:19:15 +0000 | [diff] [blame] | 59 | } ldiv_t; |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 60 | |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 61 | #define __max(a,b) (((a) > (b)) ? (a) : (b)) |
| 62 | #define __min(a,b) (((a) < (b)) ? (a) : (b)) |
| 63 | #ifndef __cplusplus |
| 64 | #define max(a,b) (((a) > (b)) ? (a) : (b)) |
| 65 | #define min(a,b) (((a) < (b)) ? (a) : (b)) |
| 66 | #endif |
| 67 | |
Francois Gouget | 79027d1 | 2002-11-30 01:52:30 +0000 | [diff] [blame] | 68 | /* _set_error_mode() constants */ |
| 69 | #define _OUT_TO_DEFAULT 0 |
| 70 | #define _OUT_TO_STDERR 1 |
| 71 | #define _OUT_TO_MSGBOX 2 |
| 72 | #define _REPORT_ERRMODE 3 |
| 73 | |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 74 | |
| 75 | #ifdef __cplusplus |
| 76 | extern "C" { |
| 77 | #endif |
| 78 | |
Alexandre Julliard | e2b3ee5 | 2008-12-15 16:20:08 +0100 | [diff] [blame] | 79 | #ifdef __i386__ |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 80 | |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 81 | extern unsigned int* __cdecl __p__osver(void); |
Alexandre Julliard | e2b3ee5 | 2008-12-15 16:20:08 +0100 | [diff] [blame] | 82 | #define _osver (*__p__osver()) |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 83 | extern unsigned int* __cdecl __p__winver(void); |
Alexandre Julliard | e2b3ee5 | 2008-12-15 16:20:08 +0100 | [diff] [blame] | 84 | #define _winver (*__p__winver()) |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 85 | extern unsigned int* __cdecl __p__winmajor(void); |
Alexandre Julliard | e2b3ee5 | 2008-12-15 16:20:08 +0100 | [diff] [blame] | 86 | #define _winmajor (*__p__winmajor()) |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 87 | extern unsigned int* __cdecl __p__winminor(void); |
Alexandre Julliard | e2b3ee5 | 2008-12-15 16:20:08 +0100 | [diff] [blame] | 88 | #define _winminor (*__p__winminor()) |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 89 | extern int* __cdecl __p___argc(void); |
Alexandre Julliard | e2b3ee5 | 2008-12-15 16:20:08 +0100 | [diff] [blame] | 90 | #define __argc (*__p___argc()) |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 91 | extern char*** __cdecl __p___argv(void); |
Alexandre Julliard | e2b3ee5 | 2008-12-15 16:20:08 +0100 | [diff] [blame] | 92 | #define __argv (*__p___argv()) |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 93 | extern wchar_t*** __cdecl __p___wargv(void); |
Alexandre Julliard | e2b3ee5 | 2008-12-15 16:20:08 +0100 | [diff] [blame] | 94 | #define __wargv (*__p___wargv()) |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 95 | extern char*** __cdecl __p__environ(void); |
Alexandre Julliard | e2b3ee5 | 2008-12-15 16:20:08 +0100 | [diff] [blame] | 96 | #define _environ (*__p__environ()) |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 97 | extern wchar_t*** __cdecl __p__wenviron(void); |
Alexandre Julliard | e2b3ee5 | 2008-12-15 16:20:08 +0100 | [diff] [blame] | 98 | #define _wenviron (*__p__wenviron()) |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 99 | extern unsigned int* __cdecl __p__fmode(void); |
Alexandre Julliard | e2b3ee5 | 2008-12-15 16:20:08 +0100 | [diff] [blame] | 100 | #define _fmode (*__p__fmode()) |
| 101 | |
| 102 | #else /* __i386__ */ |
| 103 | |
| 104 | extern unsigned int _osver; |
| 105 | extern unsigned int _winver; |
| 106 | extern unsigned int _winmajor; |
| 107 | extern unsigned int _winminor; |
| 108 | extern int __argc; |
| 109 | extern char **__argv; |
| 110 | extern wchar_t **__wargv; |
| 111 | extern char **_environ; |
| 112 | extern wchar_t **_wenviron; |
| 113 | extern unsigned int _fmode; |
| 114 | |
| 115 | #endif /* __i386__ */ |
| 116 | |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 117 | extern int* __cdecl ___mb_cur_max_func(void); |
| 118 | #define __mb_cur_max (*___mb_cur_max_func()) |
| 119 | extern unsigned long* __cdecl __doserrno(void); |
| 120 | #define _doserrno (*__doserrno()) |
| 121 | extern int* __cdecl _errno(void); |
| 122 | #define errno (*_errno()) |
Alexandre Julliard | e2b3ee5 | 2008-12-15 16:20:08 +0100 | [diff] [blame] | 123 | |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 124 | /* FIXME: We need functions to access these: |
| 125 | * int _sys_nerr; |
| 126 | * char** _sys_errlist; |
| 127 | */ |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 128 | |
| 129 | |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 130 | typedef int (__cdecl *_onexit_t)(void); |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 131 | |
| 132 | |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 133 | int __cdecl _atodbl(_CRT_DOUBLE*,char*); |
| 134 | int __cdecl _atoflt(_CRT_FLOAT*,char*); |
| 135 | __int64 __cdecl _atoi64(const char*); |
| 136 | long double __cdecl _atold(const char*); |
| 137 | int __cdecl _atoldbl(_LDOUBLE*,char*); |
| 138 | void __cdecl _beep(unsigned int,unsigned int); |
| 139 | char* __cdecl _ecvt(double,int,int*,int*); |
| 140 | char* __cdecl _fcvt(double,int,int*,int*); |
| 141 | char* __cdecl _fullpath(char*,const char*,size_t); |
| 142 | char* __cdecl _gcvt(double,int,char*); |
| 143 | char* __cdecl _i64toa(__int64,char*,int); |
| 144 | char* __cdecl _itoa(int,char*,int); |
| 145 | char* __cdecl _ltoa(long,char*,int); |
| 146 | unsigned long __cdecl _lrotl(unsigned long,int); |
| 147 | unsigned long __cdecl _lrotr(unsigned long,int); |
| 148 | void __cdecl _makepath(char*,const char*,const char*,const char*,const char*); |
| 149 | size_t __cdecl _mbstrlen(const char*); |
| 150 | _onexit_t __cdecl _onexit(_onexit_t); |
| 151 | int __cdecl _putenv(const char*); |
| 152 | unsigned int __cdecl _rotl(unsigned int,int); |
| 153 | unsigned int __cdecl _rotr(unsigned int,int); |
| 154 | void __cdecl _searchenv(const char*,const char*,char*); |
| 155 | int __cdecl _set_error_mode(int); |
| 156 | void __cdecl _seterrormode(int); |
| 157 | void __cdecl _sleep(unsigned long); |
| 158 | void __cdecl _splitpath(const char*,char*,char*,char*,char*); |
| 159 | long double __cdecl _strtold(const char*,char**); |
| 160 | void __cdecl _swab(char*,char*,int); |
| 161 | char* __cdecl _ui64toa(unsigned __int64,char*,int); |
| 162 | char* __cdecl _ultoa(unsigned long,char*,int); |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 163 | |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 164 | void __cdecl _exit(int); |
| 165 | void __cdecl abort(void); |
| 166 | int __cdecl abs(int); |
| 167 | int __cdecl atexit(void (*)(void)); |
| 168 | double __cdecl atof(const char*); |
| 169 | int __cdecl atoi(const char*); |
| 170 | long __cdecl atol(const char*); |
| 171 | void* __cdecl calloc(size_t,size_t); |
Alexandre Julliard | 0b19a6f | 2003-11-28 23:17:28 +0000 | [diff] [blame] | 172 | #ifndef __i386__ |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 173 | div_t __cdecl div(int,int); |
| 174 | ldiv_t __cdecl ldiv(long,long); |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 175 | #endif |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 176 | void __cdecl exit(int); |
| 177 | void __cdecl free(void*); |
| 178 | char* __cdecl getenv(const char*); |
| 179 | long __cdecl labs(long); |
| 180 | void* __cdecl malloc(size_t); |
| 181 | int __cdecl mblen(const char*,size_t); |
| 182 | void __cdecl perror(const char*); |
| 183 | int __cdecl rand(void); |
| 184 | void* __cdecl realloc(void*,size_t); |
| 185 | void __cdecl srand(unsigned int); |
| 186 | double __cdecl strtod(const char*,char**); |
| 187 | long __cdecl strtol(const char*,char**,int); |
| 188 | unsigned long __cdecl strtoul(const char*,char**,int); |
| 189 | int __cdecl system(const char*); |
| 190 | void* __cdecl bsearch(const void*,const void*,size_t,size_t,int (*)(const void*,const void*)); |
| 191 | void __cdecl qsort(void*,size_t,size_t,int (*)(const void*,const void*)); |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 192 | |
Dimitrie O. Paun | 0377462 | 2004-06-25 01:19:15 +0000 | [diff] [blame] | 193 | #ifndef _WSTDLIB_DEFINED |
| 194 | #define _WSTDLIB_DEFINED |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 195 | wchar_t* __cdecl _itow(int,wchar_t*,int); |
| 196 | wchar_t* __cdecl _i64tow(__int64,wchar_t*,int); |
| 197 | wchar_t* __cdecl _ltow(long,wchar_t*,int); |
| 198 | wchar_t* __cdecl _ui64tow(unsigned __int64,wchar_t*,int); |
| 199 | wchar_t* __cdecl _ultow(unsigned long,wchar_t*,int); |
| 200 | wchar_t* __cdecl _wfullpath(wchar_t*,const wchar_t*,size_t); |
| 201 | wchar_t* __cdecl _wgetenv(const wchar_t*); |
| 202 | void __cdecl _wmakepath(wchar_t*,const wchar_t*,const wchar_t*,const wchar_t*,const wchar_t*); |
| 203 | void __cdecl _wperror(const wchar_t*); |
| 204 | int __cdecl _wputenv(const wchar_t*); |
| 205 | void __cdecl _wsearchenv(const wchar_t*,const wchar_t*,wchar_t*); |
| 206 | void __cdecl _wsplitpath(const wchar_t*,wchar_t*,wchar_t*,wchar_t*,wchar_t*); |
| 207 | int __cdecl _wsystem(const wchar_t*); |
| 208 | int __cdecl _wtoi(const wchar_t*); |
| 209 | __int64 __cdecl _wtoi64(const wchar_t*); |
| 210 | long __cdecl _wtol(const wchar_t*); |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 211 | |
Alexandre Julliard | bb33b0a | 2008-12-17 14:45:18 +0100 | [diff] [blame] | 212 | size_t __cdecl mbstowcs(wchar_t*,const char*,size_t); |
| 213 | int __cdecl mbtowc(wchar_t*,const char*,size_t); |
| 214 | double __cdecl wcstod(const wchar_t*,wchar_t**); |
| 215 | long __cdecl wcstol(const wchar_t*,wchar_t**,int); |
| 216 | size_t __cdecl wcstombs(char*,const wchar_t*,size_t); |
| 217 | unsigned long __cdecl wcstoul(const wchar_t*,wchar_t**,int); |
| 218 | int __cdecl wctomb(char*,wchar_t); |
Dimitrie O. Paun | 0377462 | 2004-06-25 01:19:15 +0000 | [diff] [blame] | 219 | #endif /* _WSTDLIB_DEFINED */ |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 220 | |
| 221 | #ifdef __cplusplus |
| 222 | } |
| 223 | #endif |
| 224 | |
| 225 | |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 226 | #define environ _environ |
| 227 | #define onexit_t _onexit_t |
| 228 | |
Madhura Sahasrabudhe | 992d1b9 | 2003-03-22 21:15:41 +0000 | [diff] [blame] | 229 | static inline char* ecvt(double value, int ndigit, int* decpt, int* sign) { return _ecvt(value, ndigit, decpt, sign); } |
| 230 | static inline char* fcvt(double value, int ndigit, int* decpt, int* sign) { return _fcvt(value, ndigit, decpt, sign); } |
| 231 | static inline char* gcvt(double value, int ndigit, char* buf) { return _gcvt(value, ndigit, buf); } |
| 232 | static inline char* itoa(int value, char* str, int radix) { return _itoa(value, str, radix); } |
| 233 | static inline char* ltoa(long value, char* str, int radix) { return _ltoa(value, str, radix); } |
| 234 | static inline _onexit_t onexit(_onexit_t func) { return _onexit(func); } |
| 235 | static inline int putenv(const char* str) { return _putenv(str); } |
Jon Griffiths | 5f17550 | 2003-07-18 22:57:15 +0000 | [diff] [blame] | 236 | static inline void swab(char* src, char* dst, int len) { _swab(src, dst, len); } |
Madhura Sahasrabudhe | 992d1b9 | 2003-03-22 21:15:41 +0000 | [diff] [blame] | 237 | static inline char* ultoa(unsigned long value, char* str, int radix) { return _ultoa(value, str, radix); } |
Alexandre Julliard | 0b19a6f | 2003-11-28 23:17:28 +0000 | [diff] [blame] | 238 | |
| 239 | #ifdef __i386__ |
| 240 | static inline div_t __wine_msvcrt_div(int num, int denom) |
| 241 | { |
| 242 | extern unsigned __int64 div(int,int); |
| 243 | div_t ret; |
| 244 | unsigned __int64 res = div(num,denom); |
| 245 | ret.quot = (int)res; |
| 246 | ret.rem = (int)(res >> 32); |
| 247 | return ret; |
| 248 | } |
| 249 | static inline ldiv_t __wine_msvcrt_ldiv(long num, long denom) |
| 250 | { |
| 251 | extern unsigned __int64 ldiv(long,long); |
| 252 | ldiv_t ret; |
| 253 | unsigned __int64 res = ldiv(num,denom); |
| 254 | ret.quot = (long)res; |
| 255 | ret.rem = (long)(res >> 32); |
| 256 | return ret; |
| 257 | } |
| 258 | #define div(num,denom) __wine_msvcrt_div(num,denom) |
| 259 | #define ldiv(num,denom) __wine_msvcrt_ldiv(num,denom) |
| 260 | #endif |
| 261 | |
Dmitry Timoshkov | 2af96fe | 2007-02-20 16:35:41 +0800 | [diff] [blame] | 262 | #include <poppack.h> |
| 263 | |
Francois Gouget | eee695d | 2001-04-10 23:21:43 +0000 | [diff] [blame] | 264 | #endif /* __WINE_STDLIB_H */ |