|
0
|
1 #ifndef CYGONCE_LIBC_STDLIB_H |
|
|
2 #define CYGONCE_LIBC_STDLIB_H |
|
|
3 //======================================================================== |
|
|
4 // |
|
|
5 // stdlib.h |
|
|
6 // |
|
|
7 // ISO C standard utility functions (ISO C standard section 7.10) |
|
|
8 // |
|
|
9 //======================================================================== |
|
|
10 //####COPYRIGHTBEGIN#### |
|
|
11 // |
|
|
12 // ------------------------------------------- |
|
|
13 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
14 // Version 1.0 (the "License"); you may not use this file except in |
|
|
15 // compliance with the License. You may obtain a copy of the License at |
|
|
16 // http://sourceware.cygnus.com/ecos |
|
|
17 // |
|
|
18 // Software distributed under the License is distributed on an "AS IS" |
|
|
19 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
20 // License for the specific language governing rights and limitations under |
|
|
21 // the License. |
|
|
22 // |
|
|
23 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
24 // September 30, 1998. |
|
|
25 // |
|
|
26 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
27 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
28 // ------------------------------------------- |
|
|
29 // |
|
|
30 //####COPYRIGHTEND#### |
|
|
31 //======================================================================== |
|
|
32 //#####DESCRIPTIONBEGIN#### |
|
|
33 // |
|
2
|
34 // Author(s): jlarmour |
|
|
35 // Contributors: jlarmour |
|
|
36 // Date: 1999-03-17 |
|
0
|
37 // Purpose: |
|
|
38 // Description: |
|
2
|
39 // Usage: #include <stdlib.h> |
|
0
|
40 // |
|
|
41 //####DESCRIPTIONEND#### |
|
|
42 // |
|
|
43 //======================================================================== |
|
|
44 |
|
|
45 // CONFIGURATION |
|
|
46 |
|
|
47 #include <pkgconf/libc.h> // Configuration header |
|
|
48 |
|
|
49 // INCLUDES |
|
|
50 |
|
|
51 #include <cyg/infra/cyg_type.h> // Common type definitions and support |
|
|
52 #include <stddef.h> // NULL, wchar_t and size_t from compiler |
|
|
53 #include <limits.h> // for INT_MAX definition used below |
|
|
54 |
|
|
55 // CONSTANTS |
|
|
56 |
|
2
|
57 // as described in ISO para 7.10 |
|
0
|
58 |
|
|
59 // codes to pass to exit() |
|
|
60 |
|
2
|
61 // Successful exit status - must be zero (POSIX 1003.1 8.1) |
|
|
62 #define EXIT_SUCCESS 0 |
|
|
63 // Failing exit status - must be non-zero (POSIX 1003.1 8.1) |
|
|
64 #define EXIT_FAILURE 1 |
|
0
|
65 |
|
|
66 // Maximum value returned by rand() |
|
|
67 |
|
|
68 #define RAND_MAX INT_MAX |
|
|
69 |
|
|
70 |
|
|
71 // Maximum number of bytes in a multibyte character for the current locale |
|
|
72 |
|
|
73 #define MB_CUR_MAX 1 |
|
|
74 |
|
|
75 |
|
|
76 // TYPE DEFINITIONS |
|
|
77 |
|
|
78 // as described in ANSI para 7.10 |
|
|
79 |
|
|
80 // return type of the div() function |
|
|
81 |
|
|
82 typedef struct { |
|
|
83 int quot; // quotient |
|
|
84 int rem; // remainder |
|
|
85 } div_t; |
|
|
86 |
|
|
87 |
|
|
88 // return type of the ldiv() function |
|
|
89 |
|
|
90 typedef struct { |
|
|
91 long quot; // quotient |
|
|
92 long rem; // remainder |
|
|
93 } ldiv_t; |
|
|
94 |
|
|
95 // Unofficial type of comparison function used by both bsearch() and |
|
|
96 // qsort() |
|
|
97 |
|
|
98 typedef int (*Cyg_comparison_fn_t)(const void * /* object1 */, |
|
|
99 const void * /* object2 */); |
|
|
100 |
|
|
101 // Similarly, type of function used by atexit() |
|
2
|
102 typedef void (*Cyg_libc_atexit_fn_t)( void ); |
|
0
|
103 |
|
|
104 |
|
|
105 // FUNCTION PROTOTYPES |
|
|
106 |
|
|
107 //======================================================================== |
|
|
108 |
|
|
109 // 7.10.1 String conversion functions |
|
|
110 |
|
|
111 externC double |
|
|
112 atof( const char * /* double_str */ ); |
|
|
113 |
|
|
114 externC int |
|
|
115 atoi( const char * /* int_str */ ); |
|
|
116 |
|
|
117 externC long |
|
|
118 atol( const char * /* long_str */ ); |
|
|
119 |
|
|
120 externC double |
|
|
121 strtod( const char * /* double_str */, char ** /* endptr */ ); |
|
|
122 |
|
|
123 externC long |
|
|
124 strtol( const char * /* long_str */, char ** /* endptr */, |
|
|
125 int /* base */ ); |
|
|
126 |
|
|
127 externC unsigned long |
|
|
128 strtoul( const char * /* ulong_str */, char ** /* endptr */, |
|
|
129 int /* base */ ); |
|
|
130 |
|
|
131 //======================================================================== |
|
|
132 |
|
|
133 // 7.10.2 Pseudo-random sequence generation functions |
|
|
134 |
|
|
135 externC int |
|
|
136 rand( void ); |
|
|
137 |
|
|
138 externC void |
|
|
139 srand( unsigned int /* seed */ ); |
|
|
140 |
|
|
141 // POSIX 1003.1 section 8.3.8 rand_r() |
|
|
142 externC int |
|
|
143 rand_r( unsigned int * /* seed */ ); |
|
|
144 |
|
|
145 //======================================================================== |
|
|
146 |
|
|
147 // 7.10.3 Memory management functions |
|
|
148 |
|
|
149 #ifdef CYGPKG_LIBC_MALLOC |
|
|
150 |
|
|
151 externC void * |
|
|
152 calloc( size_t /* num_objects */, size_t /* object_size */ ); |
|
|
153 |
|
|
154 externC void |
|
|
155 free( void * /* ptr */ ); |
|
|
156 |
|
|
157 externC void * |
|
|
158 malloc( size_t /* size */ ); |
|
|
159 |
|
|
160 externC void * |
|
|
161 realloc( void * /* ptr */, size_t /* size */ ); |
|
|
162 |
|
|
163 #endif // ifdef CYGPKG_LIBC_MALLOC |
|
|
164 |
|
|
165 //======================================================================== |
|
|
166 |
|
|
167 // 7.10.4 Communication with the environment |
|
|
168 |
|
|
169 externC void |
|
2
|
170 abort( void ) CYGBLD_ATTRIB_NORET; |
|
0
|
171 |
|
|
172 externC int |
|
2
|
173 atexit( Cyg_libc_atexit_fn_t /* func_to_register */ ); |
|
0
|
174 |
|
|
175 externC void |
|
2
|
176 exit( int /* status */ ) CYGBLD_ATTRIB_NORET; |
|
0
|
177 |
|
|
178 /* POSIX 1003.1 section 3.2.2 "Terminate a process" */ |
|
|
179 |
|
|
180 externC void |
|
2
|
181 _exit( int /* status */ ) CYGBLD_ATTRIB_NORET; |
|
0
|
182 |
|
|
183 externC char * |
|
|
184 getenv( const char * /* name */ ); |
|
|
185 |
|
2
|
186 externC int |
|
|
187 system( const char * /* command */ ); |
|
|
188 |
|
0
|
189 |
|
|
190 //======================================================================== |
|
|
191 |
|
|
192 // 7.10.5 Searching and sorting utilities |
|
|
193 |
|
|
194 externC void * |
|
|
195 bsearch( const void * /* search_key */, const void * /* first_object */, |
|
|
196 size_t /* num_objects */, size_t /* object_size */, |
|
|
197 Cyg_comparison_fn_t /* comparison_fn */ ); |
|
|
198 |
|
|
199 externC void |
|
|
200 qsort( void * /* first_object */, size_t /* num_objects */, |
|
|
201 size_t /* object_size */, Cyg_comparison_fn_t /* comparison_fn */ ); |
|
|
202 |
|
|
203 |
|
|
204 //======================================================================== |
|
|
205 |
|
|
206 // 7.10.6 Integer arithmetic functions |
|
|
207 |
|
|
208 externC int |
|
2
|
209 abs( int /* val */ ) CYGBLD_ATTRIB_CONST; |
|
0
|
210 |
|
|
211 externC div_t |
|
2
|
212 div( int /* numerator */, int /* denominator */ ) CYGBLD_ATTRIB_CONST; |
|
0
|
213 |
|
|
214 externC long |
|
2
|
215 labs( long /* val */ ) CYGBLD_ATTRIB_CONST; |
|
0
|
216 |
|
|
217 externC ldiv_t |
|
2
|
218 ldiv( long /* numerator */, long /* denominator */ ) CYGBLD_ATTRIB_CONST; |
|
0
|
219 |
|
|
220 //======================================================================== |
|
|
221 |
|
2
|
222 // NON-STANDARD FUNCTIONS |
|
|
223 |
|
|
224 ///////////////////// |
|
|
225 // cyg_libc_itoa() // |
|
|
226 ///////////////////// |
|
|
227 // |
|
|
228 // This converts num to a string and puts it into s padding with |
|
|
229 // "0"'s if padzero is set, or spaces otherwise if necessary. |
|
|
230 // The number of chars written to s is returned |
|
|
231 // |
|
|
232 |
|
|
233 externC cyg_uint8 |
|
|
234 cyg_libc_itoa( cyg_uint8 *__s, cyg_int32 __num, cyg_uint8 __width, |
|
|
235 cyg_bool __padzero ); |
|
|
236 |
|
|
237 //======================================================================== |
|
|
238 |
|
|
239 |
|
0
|
240 // INLINE FUNCTIONS |
|
|
241 |
|
|
242 #ifdef CYGIMP_LIBC_STDLIB_INLINES |
|
|
243 #include <stdlib.inl> |
|
|
244 #endif |
|
|
245 |
|
|
246 #endif // CYGONCE_LIBC_STDLIB_H multiple inclusion protection |
|
|
247 |
|
|
248 // EOF stdlib.h |