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