branch update for HEAD-2003021201
[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 /* 
45  * These values may be used as exit status codes.
46  */
47 #define EXIT_SUCCESS    0
48 #define EXIT_FAILURE    -1
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 /*
55  * This seems like a convenient place to declare these variables, which
56  * give programs using WinMain (or main for that matter) access to main-ish
57  * argc and argv. environ is a pointer to a table of environment variables.
58  * NOTE: Strings in _argv and environ are ANSI strings.
59  */
60 extern int* __argc_dll;
61 extern char*** __argv_dll;
62 extern char*** _environ_dll;
63
64 #define __argc   (*__argc_dll)
65 #define __argv   (*__argv_dll)
66 #define _environ (*_environ_dll)
67
68
69 #include <msvcrt/mbstring.h>
70
71 #ifndef __ATTRIB_NORETURN
72 #ifdef  __GNUC__
73 #define _ATTRIB_NORETURN    __attribute__ ((noreturn))
74 #ifndef __int64
75 #define __int64     long long
76 #endif  /* Not __int64 */
77 #else   /* Not __GNUC__ */
78 #define _ATTRIB_NORETURN
79 #endif  /* __GNUC__ */
80 #endif
81
82 double atof(const char* szNumber);
83 int atoi(const char* szNumber);
84 long atol(const char* szNumber);
85
86 double strtod(const char* szNumber, char** pszAfterNumber);
87 double wcstod(const wchar_t* wsNumber, wchar_t** pwsAfterNumber);
88 long strtol(const char* szNumber, char** pszAfterNumber, int nBase);
89 long wcstol(const wchar_t* wsNumber, wchar_t** pwsAfterNumber, int nBase);
90
91 unsigned long strtoul(const char* szNumber, char** pszAfterNumber, int nBase);
92 unsigned long wcstoul(const wchar_t* wsNumber, wchar_t** pwsAfterNumber, int nBase);
93
94 size_t wcstombs(char* mbsDest, const wchar_t* wsConvert, size_t size);
95 int wctomb(char* mbDest, wchar_t wc);
96 int mblen(const char* mbs, size_t sizeString);
97 size_t mbstowcs(wchar_t* wcaDest, const char* mbsConvert, size_t size);
98 int mbtowc(wchar_t* wcDest, const char* mbConvert, size_t size);
99
100 int rand(void);
101 void srand(unsigned int nSeed);
102
103 void* calloc(size_t sizeObjCnt, size_t sizeObject);
104 void* malloc(size_t sizeObject);
105 void* realloc(void* pObject, size_t sizeNew);
106 void free(void* pObject);
107
108 void abort(void)  _ATTRIB_NORETURN;
109 void exit(int nStatus) _ATTRIB_NORETURN;
110 int atexit(void (*pfuncExitProcessing)(void));
111
112 int system(const char* szCommand); // impl in process
113 char* getenv(const char* szVarName); // impl in stdio ???
114 wchar_t* _wgetenv(const wchar_t* szVarName);
115
116 typedef int (*_pfunccmp_t)(const void*, const void*);
117
118 void* bsearch(const void* pKey, const void* pBase, size_t cntObjects, size_t sizeObject, _pfunccmp_t pfuncCmp);
119 void qsort(const void* pBase, size_t cntObjects, size_t sizeObject, _pfunccmp_t pfuncCmp);
120
121 int abs(int n);
122 long labs(long n);
123
124 /*
125  * div_t and ldiv_t are structures used to return the results of div and
126  * ldiv.
127  *
128  * NOTE: div and ldiv appear not to work correctly unless
129  *       -fno-pcc-struct-return is specified. This is included in the
130  *       mingw32 specs file.
131  */
132 typedef struct { int quot, rem; } div_t;
133 typedef struct { long quot, rem; } ldiv_t;
134
135 #ifdef  __GNUC__ // robd
136 typedef struct { long long quot, rem; } lldiv_t;
137 #else
138 typedef struct { double quot, rem; } lldiv_t;
139 #endif
140
141 div_t div(int nNumerator, int nDenominator);
142 ldiv_t ldiv(long lNumerator, long lDenominator);
143
144 #ifdef  __GNUC__ // robd
145 lldiv_t lldiv(long long lNumerator, long long lDenominator);
146 #else
147 lldiv_t lldiv(double lNumerator, double lDenominator);
148 #endif
149
150
151 #ifndef __STRICT_ANSI__
152
153 /*
154  * NOTE: Officially the three following functions are obsolete. The Win32 API
155  *       functions SetErrorMode, Beep and Sleep are their replacements.
156  */
157 void     _beep(unsigned int, unsigned int);
158 void     _seterrormode(int nMode);
159 void     _sleep(unsigned long ulTime);
160
161 void     _exit(int nStatus) _ATTRIB_NORETURN;
162
163 int      _putenv(const char *val);
164 void     _searchenv(const char *file, const char *var, char *path);
165 void     _splitpath(const char *path, char *drive, char *dir, char *fname, char *ext);
166
167 char*    _itoa(int nValue, char* sz, int nRadix);
168 char*    _ltoa(long lnValue, char* sz, int nRadix);
169
170 int      _wputenv(const wchar_t *val);
171 void     _wsearchenv(const wchar_t *file, const wchar_t *var, wchar_t *path);
172 void     _makepath(char *path, const char *drive, const char *dir, const char *fname, const char *ext);
173 void     _wmakepath(wchar_t *path, const wchar_t *drive, const wchar_t *dir, const wchar_t *fname, const wchar_t *ext);
174 wchar_t* _wfullpath(wchar_t *absPath, const wchar_t *relPath, size_t maxLength);
175 char*    _i64toa(__int64 value, char *string, int radix);
176 char*    _ultoa(unsigned long value, char *string, int radix);
177 char*    _ui64toa(unsigned __int64 value, char *string, int radix);
178
179 wchar_t* _itow(int nValue, wchar_t* sz, int nRadix);
180 wchar_t* _i64tow(__int64 value, wchar_t *string, int radix);
181 wchar_t* _ltow(long lnValue, wchar_t* sz, int nRadix);
182 wchar_t* _ultow(unsigned long value, wchar_t *string, int radix);
183 wchar_t* _ui64tow(unsigned __int64 value, wchar_t *string, int radix);
184 __int64  _atoi64(const char *szNumber);
185 int      _wtoi(const wchar_t *str);
186 __int64  _wtoi64(const wchar_t *str);
187 long     _wtol(const wchar_t *str);
188
189 char*    _ecvt(double dValue, int nDig, int* pnDec, int* pnSign);
190 char*    _fcvt(double dValue, int nDig, int* pnDec, int* pnSign);
191 char*    _gcvt(double dValue, int nDec, char* caBuf);
192 char*    _fullpath(char* caBuf, const char* szPath, size_t sizeMax);
193 void     _swab(const char* caFrom, char* caTo, size_t sizeToCopy);
194
195 unsigned int _rotl(unsigned int value, int shift);
196 unsigned int _rotr(unsigned int value, int shift);
197 unsigned long _lrotl(unsigned long value, int shift);
198 unsigned long _lrotr(unsigned long value, int shift);
199
200
201 #ifndef _NO_OLDNAMES
202 #define  beep         _beep
203 #define  seterrormode _seterrormode
204 #define  sleep        _sleep
205 #define  putenv       _putenv
206 #define  searchenv    _searchenv
207 #define  splitpath    _splitpath
208 #define  itoa         _itoa
209 #define  ltoa         _ltoa
210 #define  ecvt         _ecvt
211 #define  fcvt         _fcvt
212 #define  gcvt         _gcvt
213 #define  swab         _swab
214 #endif  /* Not _NO_OLDNAMES */
215
216
217 #endif  /* Not __STRICT_ANSI__ */
218
219 /*
220  * Undefine the no return attribute used in some function definitions
221  */
222 #undef  _ATTRIB_NORETURN
223
224 #ifdef __cplusplus
225 }
226 #endif
227
228 #endif  /* Not _STDLIB_H_ */
229