update for HEAD-2003091401
[reactos.git] / include / msvcrt / stdlib.h
1 /*
2  * stdlib.h
3  *
4  * Definitions for common types, variables, and functions.
5  *
6  * This file is part of the Mingw32 package.
7  *
8  * Contributors:
9  *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
10  *
11  *  THIS SOFTWARE IS NOT COPYRIGHTED
12  *
13  *  This source code is offered for use in the public domain. You may
14  *  use, modify or distribute it freely.
15  *
16  *  This code is distributed in the hope that it will be useful but
17  *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
18  *  DISCLAIMED. This includes but is not limited to warranties of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  * $Revision$
22  * $Author$
23  * $Date$
24  *
25  */
26 /* Appropriated for Reactos Crtdll by Ariadne */
27 /* added splitpath */
28 /* changed definition of environ and argc */
29 /* moved prototype for swab from string.h to stdlib.h */
30 #ifndef _STDLIB_H_
31 #define _STDLIB_H_
32
33 #define __need_size_t
34 #define __need_wchar_t
35 #define __need_NULL
36 #include <msvcrt/stddef.h>
37
38 /*
39  * RAND_MAX is the maximum value that may be returned by rand.
40  * The minimum is zero.
41  */
42 #define RAND_MAX    0x7FFF
43
44 #ifndef _MAX_PATH
45 #define _MAX_DRIVE          3
46 #define _MAX_FNAME          256
47 #define _MAX_DIR            _MAX_FNAME
48 #define _MAX_EXT            _MAX_FNAME
49 #define _MAX_PATH           260
50 #endif
51
52 /* 
53  * These values may be used as exit status codes.
54  */
55 #define EXIT_SUCCESS    0
56 #define EXIT_FAILURE    -1
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62 /*
63  * This seems like a convenient place to declare these variables, which
64  * give programs using WinMain (or main for that matter) access to main-ish
65  * argc and argv. environ is a pointer to a table of environment variables.
66  * NOTE: Strings in _argv and environ are ANSI strings.
67  */
68 extern int* __argc_dll;
69 extern char*** __argv_dll;
70 extern char*** _environ_dll;
71
72 #define __argc   (*__argc_dll)
73 #define __argv   (*__argv_dll)
74 #define _environ (*_environ_dll)
75
76
77 #include <msvcrt/mbstring.h>
78
79 #ifndef __ATTRIB_NORETURN
80 #ifdef  __GNUC__
81 #define _ATTRIB_NORETURN    __attribute__ ((noreturn))
82 #ifndef __int64
83 #define __int64     long long
84 #endif  /* Not __int64 */
85 #else   /* Not __GNUC__ */
86 #define _ATTRIB_NORETURN
87 #endif  /* __GNUC__ */
88 #endif
89
90 double atof(const char* szNumber);
91 int atoi(const char* szNumber);
92 long atol(const char* szNumber);
93
94 double strtod(const char* szNumber, char** pszAfterNumber);
95 double wcstod(const wchar_t* wsNumber, wchar_t** pwsAfterNumber);
96 long strtol(const char* szNumber, char** pszAfterNumber, int nBase);
97 long wcstol(const wchar_t* wsNumber, wchar_t** pwsAfterNumber, int nBase);
98
99 unsigned long strtoul(const char* szNumber, char** pszAfterNumber, int nBase);
100 unsigned long wcstoul(const wchar_t* wsNumber, wchar_t** pwsAfterNumber, int nBase);
101
102 size_t wcstombs(char* mbsDest, const wchar_t* wsConvert, size_t size);
103 int wctomb(char* mbDest, wchar_t wc);
104 int mblen(const char* mbs, size_t sizeString);
105 size_t mbstowcs(wchar_t* wcaDest, const char* mbsConvert, size_t size);
106 int mbtowc(wchar_t* wcDest, const char* mbConvert, size_t size);
107
108 int rand(void);
109 void srand(unsigned int nSeed);
110
111 void* calloc(size_t sizeObjCnt, size_t sizeObject);
112 void* malloc(size_t sizeObject);
113 void* realloc(void* pObject, size_t sizeNew);
114 void free(void* pObject);
115
116 void abort(void)  _ATTRIB_NORETURN;
117 void exit(int nStatus) _ATTRIB_NORETURN;
118 int atexit(void (*pfuncExitProcessing)(void));
119
120 int system(const char* szCommand); // impl in process
121 char* getenv(const char* szVarName); // impl in stdio ???
122 wchar_t* _wgetenv(const wchar_t* szVarName);
123
124 typedef int (*_pfunccmp_t)(const void*, const void*);
125
126 void* bsearch(const void* pKey, const void* pBase, size_t cntObjects, size_t sizeObject, _pfunccmp_t pfuncCmp);
127 void qsort(const void* pBase, size_t cntObjects, size_t sizeObject, _pfunccmp_t pfuncCmp);
128
129 int abs(int n);
130 long labs(long n);
131
132 /*
133  * div_t and ldiv_t are structures used to return the results of div and
134  * ldiv.
135  *
136  * NOTE: div and ldiv appear not to work correctly unless
137  *       -fno-pcc-struct-return is specified. This is included in the
138  *       mingw32 specs file.
139  */
140 typedef struct { int quot, rem; } div_t;
141 typedef struct { long quot, rem; } ldiv_t;
142
143 #ifdef  __GNUC__ // robd
144 typedef struct { long long quot, rem; } lldiv_t;
145 #else
146 typedef struct { double quot, rem; } lldiv_t;
147 #endif
148
149 div_t div(int nNumerator, int nDenominator);
150 ldiv_t ldiv(long lNumerator, long lDenominator);
151
152 #ifdef  __GNUC__ // robd
153 lldiv_t lldiv(long long lNumerator, long long lDenominator);
154 #else
155 lldiv_t lldiv(double lNumerator, double lDenominator);
156 #endif
157
158
159 #ifndef __STRICT_ANSI__
160
161 /*
162  * NOTE: Officially the three following functions are obsolete. The Win32 API
163  *       functions SetErrorMode, Beep and Sleep are their replacements.
164  */
165 void     _beep(unsigned int, unsigned int);
166 void     _seterrormode(int nMode);
167 void     _sleep(unsigned long ulTime);
168
169 void     _exit(int nStatus) _ATTRIB_NORETURN;
170
171 int      _putenv(const char *val);
172 void     _searchenv(const char *file, const char *var, char *path);
173 void     _splitpath(const char *path, char *drive, char *dir, char *fname, char *ext);
174 void     _wsplitpath(const wchar_t* path, wchar_t* drive, wchar_t* dir, wchar_t* fname, wchar_t* ext);
175
176 char*    _itoa(int nValue, char* sz, int nRadix);
177 char*    _ltoa(long lnValue, char* sz, int nRadix);
178
179 int      _wputenv(const wchar_t *val);
180 void     _wsearchenv(const wchar_t *file, const wchar_t *var, wchar_t *path);
181 void     _makepath(char *path, const char *drive, const char *dir, const char *fname, const char *ext);
182 void     _wmakepath(wchar_t *path, const wchar_t *drive, const wchar_t *dir, const wchar_t *fname, const wchar_t *ext);
183 wchar_t* _wfullpath(wchar_t *absPath, const wchar_t *relPath, size_t maxLength);
184 char*    _i64toa(__int64 value, char *string, int radix);
185 char*    _ultoa(unsigned long value, char *string, int radix);
186 char*    _ui64toa(unsigned __int64 value, char *string, int radix);
187
188 wchar_t* _itow(int nValue, wchar_t* sz, int nRadix);
189 wchar_t* _i64tow(__int64 value, wchar_t *string, int radix);
190 wchar_t* _ltow(long lnValue, wchar_t* sz, int nRadix);
191 wchar_t* _ultow(unsigned long value, wchar_t *string, int radix);
192 wchar_t* _ui64tow(unsigned __int64 value, wchar_t *string, int radix);
193 __int64  _atoi64(const char *szNumber);
194 int      _wtoi(const wchar_t *str);
195 __int64  _wtoi64(const wchar_t *str);
196 long     _wtol(const wchar_t *str);
197
198 char*    _ecvt(double dValue, int nDig, int* pnDec, int* pnSign);
199 char*    _fcvt(double dValue, int nDig, int* pnDec, int* pnSign);
200 char*    _gcvt(double dValue, int nDec, char* caBuf);
201 char*    _fullpath(char* caBuf, const char* szPath, size_t sizeMax);
202 void     _swab(const char* caFrom, char* caTo, size_t sizeToCopy);
203
204 unsigned int _rotl(unsigned int value, int shift);
205 unsigned int _rotr(unsigned int value, int shift);
206 unsigned long _lrotl(unsigned long value, int shift);
207 unsigned long _lrotr(unsigned long value, int shift);
208
209
210 #ifndef _NO_OLDNAMES
211 #define  beep         _beep
212 #define  seterrormode _seterrormode
213 #define  sleep        _sleep
214 #define  putenv       _putenv
215 #define  searchenv    _searchenv
216 #define  splitpath    _splitpath
217 #define  itoa         _itoa
218 #define  ltoa         _ltoa
219 #define  ecvt         _ecvt
220 #define  fcvt         _fcvt
221 #define  gcvt         _gcvt
222 #define  swab         _swab
223 #endif  /* Not _NO_OLDNAMES */
224
225
226 #endif  /* Not __STRICT_ANSI__ */
227
228 /*
229  * Undefine the no return attribute used in some function definitions
230  */
231 #undef  _ATTRIB_NORETURN
232
233 #ifndef _DISABLE_TIDENTS
234 #ifdef UNICODE
235 #define _tsplitpath _wsplitpath
236 #define _tmakepath _wmakepath
237 #else
238 #define _tsplitpath _splitpath
239 #define _tmakepath _makepath
240 #endif
241 #endif /* _DISABLE_TIDENTS */
242
243 #ifdef __cplusplus
244 }
245 #endif
246
247 #endif  /* Not _STDLIB_H_ */
248