]>
Commit | Line | Data |
---|---|---|
6591c335 | 1 | /* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc. |
ba1ffaa1 | 2 | This file is part of the GNU C Library. |
28f540f4 | 3 | |
ba1ffaa1 UD |
4 | The GNU C Library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public License as | |
6 | published by the Free Software Foundation; either version 2 of the | |
7 | License, or (at your option) any later version. | |
28f540f4 | 8 | |
ba1ffaa1 UD |
9 | The GNU C Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Library General Public License for more details. | |
28f540f4 | 13 | |
ba1ffaa1 UD |
14 | You should have received a copy of the GNU Library General Public |
15 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
16 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
17 | Boston, MA 02111-1307, USA. */ | |
28f540f4 RM |
18 | |
19 | /* | |
377a515b | 20 | * ISO C Standard: 4.10 GENERAL UTILITIES <stdlib.h> |
28f540f4 RM |
21 | */ |
22 | ||
23 | #ifndef _STDLIB_H | |
28f540f4 | 24 | #define _STDLIB_H 1 |
5107cf1d | 25 | |
28f540f4 RM |
26 | #include <features.h> |
27 | ||
28 | /* Get size_t, wchar_t and NULL from <stddef.h>. */ | |
29 | #define __need_size_t | |
30 | #define __need_wchar_t | |
31 | #define __need_NULL | |
32 | #include <stddef.h> | |
33 | ||
28f540f4 RM |
34 | __BEGIN_DECLS |
35 | ||
36 | /* Returned by `div'. */ | |
37 | typedef struct | |
38 | { | |
39 | int quot; /* Quotient. */ | |
40 | int rem; /* Remainder. */ | |
41 | } div_t; | |
42 | ||
43 | /* Returned by `ldiv'. */ | |
44 | typedef struct | |
45 | { | |
46 | long int quot; /* Quotient. */ | |
47 | long int rem; /* Remainder. */ | |
48 | } ldiv_t; | |
49 | ||
377a515b | 50 | #ifdef __USE_ISOC9X |
59dd8641 RM |
51 | /* Returned by `lldiv'. */ |
52 | typedef struct | |
53 | { | |
54 | long long int quot; /* Quotient. */ | |
55 | long long int rem; /* Remainder. */ | |
56 | } lldiv_t; | |
57 | #endif | |
58 | ||
28f540f4 RM |
59 | |
60 | /* The largest number rand will return (same as INT_MAX). */ | |
61 | #define RAND_MAX 2147483647 | |
62 | ||
63 | ||
64 | /* We define these the same for all machines. | |
65 | Changes from this to the outside world should be done in `_exit'. */ | |
66 | #define EXIT_FAILURE 1 /* Failing exit status. */ | |
67 | #define EXIT_SUCCESS 0 /* Successful exit status. */ | |
68 | ||
69 | ||
0200214b RM |
70 | /* Maximum length of a multibyte character in the current locale. */ |
71 | #define MB_CUR_MAX (__ctype_get_mb_cur_max ()) | |
72 | extern int __ctype_get_mb_cur_max __P ((void)); | |
28f540f4 RM |
73 | |
74 | ||
75 | /* Convert a string to a floating-point number. */ | |
76 | extern double atof __P ((__const char *__nptr)); | |
77 | /* Convert a string to an integer. */ | |
78 | extern int atoi __P ((__const char *__nptr)); | |
79 | /* Convert a string to a long integer. */ | |
80 | extern long int atol __P ((__const char *__nptr)); | |
81 | ||
2f6d1f1b | 82 | #if defined __USE_ISOC9X || (defined __GNUC__ && defined __USE_MISC) |
7cc27f44 UD |
83 | /* These functions will part of the standard C library in ISO C 9X. */ |
84 | extern long long int atoll __P ((__const char *__nptr)); | |
85 | #endif | |
86 | ||
28f540f4 | 87 | /* Convert a string to a floating-point number. */ |
2f6d1f1b UD |
88 | extern double strtod __P ((__const char *__restrict __nptr, |
89 | char **__restrict __endptr)); | |
28f540f4 RM |
90 | |
91 | #ifdef __USE_GNU | |
92 | /* Likewise for `float' and `long double' sizes of floating-point numbers. */ | |
2f6d1f1b UD |
93 | extern float strtof __P ((__const char *__restrict __nptr, |
94 | char **__restrict __endptr)); | |
95 | ||
96 | extern __long_double_t strtold __P ((__const char *__restrict __nptr, | |
97 | char **__restrict __endptr)); | |
28f540f4 RM |
98 | #endif |
99 | ||
100 | /* Convert a string to a long integer. */ | |
2f6d1f1b UD |
101 | extern long int strtol __P ((__const char *__restrict __nptr, |
102 | char **__restrict __endptr, int __base)); | |
28f540f4 | 103 | /* Convert a string to an unsigned long integer. */ |
2f6d1f1b UD |
104 | extern unsigned long int strtoul __P ((__const char *__restrict __nptr, |
105 | char **__restrict __endptr, | |
106 | int __base)); | |
28f540f4 | 107 | |
2f6d1f1b | 108 | #if defined __GNUC__ && defined __USE_BSD |
28f540f4 | 109 | /* Convert a string to a quadword integer. */ |
2f6d1f1b UD |
110 | extern long long int strtoq __P ((__const char *__restrict __nptr, |
111 | char **__restrict __endptr, int __base)); | |
28f540f4 | 112 | /* Convert a string to an unsigned quadword integer. */ |
2f6d1f1b UD |
113 | extern unsigned long long int strtouq __P ((__const char *__restrict __nptr, |
114 | char **__restrict __endptr, | |
115 | int __base)); | |
28f540f4 RM |
116 | #endif /* GCC and use BSD. */ |
117 | ||
2f6d1f1b | 118 | #if defined __USE_ISOC9X || (defined __GNUC__ && defined __USE_MISC) |
7cc27f44 UD |
119 | /* These functions will part of the standard C library in ISO C 9X. */ |
120 | ||
76060ec0 | 121 | /* Convert a string to a quadword integer. */ |
2f6d1f1b UD |
122 | extern long long int strtoll __P ((__const char *__restrict __nptr, |
123 | char **__restrict __endptr, int __base)); | |
76060ec0 | 124 | /* Convert a string to an unsigned quadword integer. */ |
2f6d1f1b UD |
125 | extern unsigned long long int strtoull __P ((__const char *__restrict __nptr, |
126 | char **__restrict __endptr, | |
127 | int __base)); | |
128 | #endif /* ISO C 9X or GCC and use MISC. */ | |
76060ec0 RM |
129 | |
130 | ||
0501d603 UD |
131 | #ifdef __USE_GNU |
132 | /* The concept of one static locale per category is not very well | |
133 | thought out. Many applications will need to process its data using | |
134 | information from several different locales. Another application is | |
135 | the implementation of the internationalization handling in the | |
136 | upcoming ISO C++ standard library. To support this another set of | |
137 | the functions using locale data exist which have an additional | |
138 | argument. | |
139 | ||
140 | Attention: all these functions are *not* standardized in any form. | |
141 | This is a proof-of-concept implementation. */ | |
142 | ||
143 | /* Structure for reentrant locale using functions. This is an | |
144 | (almost) opaque type for the user level programs. */ | |
145 | # include <xlocale.h> | |
146 | ||
147 | /* Special versions of the functions above which take the locale to | |
148 | use as an additional parameter. */ | |
149 | extern long int __strtol_l __P ((__const char *__restrict __nptr, | |
150 | char **__restrict __endptr, int __base, | |
151 | __locale_t __loc)); | |
152 | ||
153 | extern unsigned long int __strtoul_l __P ((__const char *__restrict __nptr, | |
154 | char **__restrict __endptr, | |
155 | int __base, __locale_t __loc)); | |
156 | ||
157 | extern long long int __strtoll_l __P ((__const char *__restrict __nptr, | |
158 | char **__restrict __endptr, int __base, | |
159 | __locale_t __loc)); | |
160 | ||
161 | extern unsigned long long int __strtoull_l __P ((__const char *__restrict | |
162 | __nptr, | |
163 | char **__restrict __endptr, | |
164 | int __base, | |
165 | __locale_t __loc)); | |
166 | ||
167 | extern double __strtod_l __P ((__const char *__restrict __nptr, | |
168 | char **__restrict __endptr, __locale_t __loc)); | |
169 | ||
170 | extern float __strtof_l __P ((__const char *__restrict __nptr, | |
171 | char **__restrict __endptr, __locale_t __loc)); | |
172 | ||
173 | extern __long_double_t __strtold_l __P ((__const char *__restrict __nptr, | |
174 | char **__restrict __endptr, | |
175 | __locale_t __loc)); | |
176 | #endif /* GNU */ | |
177 | ||
f0bf9cb9 RM |
178 | |
179 | /* The internal entry points for `strtoX' take an extra flag argument | |
180 | saying whether or not to parse locale-dependent number grouping. */ | |
181 | ||
2f6d1f1b UD |
182 | extern double __strtod_internal __P ((__const char *__restrict __nptr, |
183 | char **__restrict __endptr, | |
184 | int __group)); | |
185 | extern float __strtof_internal __P ((__const char *__restrict __nptr, | |
186 | char **__restrict __endptr, int __group)); | |
187 | extern __long_double_t __strtold_internal __P ((__const char * | |
188 | __restrict __nptr, | |
189 | char **__restrict __endptr, | |
190 | int __group)); | |
dfd2257a | 191 | #ifndef __strtol_internal_defined |
2f6d1f1b UD |
192 | extern long int __strtol_internal __P ((__const char *__restrict __nptr, |
193 | char **__restrict __endptr, | |
75cd5204 | 194 | int __base, int __group)); |
dfd2257a UD |
195 | # define __strtol_internal_defined 1 |
196 | #endif | |
197 | #ifndef __strtoul_internal_defined | |
2f6d1f1b UD |
198 | extern unsigned long int __strtoul_internal __P ((__const char * |
199 | __restrict __nptr, | |
200 | char **__restrict __endptr, | |
201 | int __base, int __group)); | |
dfd2257a UD |
202 | # define __strtoul_internal_defined 1 |
203 | #endif | |
204 | #if defined __GNUC__ || defined __USE_ISOC9X | |
205 | # ifndef __strtoll_internal_defined | |
2f6d1f1b UD |
206 | extern long long int __strtoll_internal __P ((__const char *__restrict __nptr, |
207 | char **__restrict __endptr, | |
208 | int __base, int __group)); | |
dfd2257a UD |
209 | # define __strtoll_internal_defined 1 |
210 | # endif | |
211 | # ifndef __strtoull_internal_defined | |
2f6d1f1b UD |
212 | extern unsigned long long int __strtoull_internal __P ((__const char * |
213 | __restrict __nptr, | |
214 | char ** | |
215 | __restrict __endptr, | |
216 | int __base, | |
217 | int __group)); | |
dfd2257a UD |
218 | # define __strtoull_internal_defined 1 |
219 | # endif | |
75cd5204 | 220 | #endif /* GCC */ |
f0bf9cb9 | 221 | |
377a515b | 222 | #if defined __OPTIMIZE__ && __GNUC__ >= 2 |
f0bf9cb9 RM |
223 | /* Define inline functions which call the internal entry points. */ |
224 | ||
2604afb1 UD |
225 | extern __inline double |
226 | strtod (__const char *__restrict __nptr, char **__restrict __endptr) | |
227 | { | |
228 | return __strtod_internal (__nptr, __endptr, 0); | |
229 | } | |
230 | extern __inline long int | |
231 | strtol (__const char *__restrict __nptr, char **__restrict __endptr, | |
232 | int __base) | |
233 | { | |
234 | return __strtol_internal (__nptr, __endptr, __base, 0); | |
235 | } | |
236 | extern __inline unsigned long int | |
237 | strtoul (__const char *__restrict __nptr, char **__restrict __endptr, | |
238 | int __base) | |
239 | { | |
240 | return __strtoul_internal (__nptr, __endptr, __base, 0); | |
241 | } | |
242 | ||
243 | # ifdef __USE_GNU | |
244 | extern __inline float | |
245 | strtof (__const char *__restrict __nptr, char **__restrict __endptr) | |
246 | { | |
247 | return __strtof_internal (__nptr, __endptr, 0); | |
248 | } | |
249 | extern __inline __long_double_t | |
250 | strtold (__const char *__restrict __nptr, char **__restrict __endptr) | |
251 | { | |
252 | return __strtold_internal (__nptr, __endptr, 0); | |
253 | } | |
254 | # endif | |
255 | ||
256 | # ifdef __USE_BSD | |
257 | extern __inline long long int | |
258 | strtoq (__const char *__restrict __nptr, char **__restrict __endptr, | |
259 | int __base) | |
260 | { | |
261 | return __strtoll_internal (__nptr, __endptr, __base, 0); | |
262 | } | |
263 | extern __inline unsigned long long int | |
264 | strtouq (__const char *__restrict __nptr, char **__restrict __endptr, | |
265 | int __base) | |
266 | { | |
267 | return __strtoull_internal (__nptr, __endptr, __base, 0); | |
268 | } | |
269 | # endif | |
270 | ||
271 | # if defined __USE_MISC || defined __USE_ISOC9X | |
272 | extern __inline long long int | |
273 | strtoll (__const char *__restrict __nptr, char **__restrict __endptr, | |
274 | int __base) | |
275 | { | |
276 | return __strtoll_internal (__nptr, __endptr, __base, 0); | |
277 | } | |
278 | extern __inline unsigned long long int | |
279 | strtoull (__const char * __restrict __nptr, char **__restrict __endptr, | |
280 | int __base) | |
281 | { | |
282 | return __strtoull_internal (__nptr, __endptr, __base, 0); | |
283 | } | |
284 | # endif | |
285 | ||
286 | extern __inline double | |
287 | atof (__const char *__nptr) | |
288 | { | |
289 | return strtod (__nptr, (char **) NULL); | |
290 | } | |
291 | extern __inline int | |
292 | atoi (__const char *__nptr) | |
293 | { | |
294 | return (int) strtol (__nptr, (char **) NULL, 10); | |
295 | } | |
296 | extern __inline long int | |
297 | atol (__const char *__nptr) | |
298 | { | |
299 | return strtol (__nptr, (char **) NULL, 10); | |
300 | } | |
301 | ||
302 | # if defined __USE_MISC || defined __USE_ISOC9X | |
303 | extern __inline long long int | |
304 | atoll (__const char *__nptr) | |
305 | { | |
306 | return strtoll (__nptr, (char **) NULL, 10); | |
307 | } | |
308 | # endif | |
28f540f4 RM |
309 | #endif /* Optimizing GCC >=2. */ |
310 | ||
311 | ||
377a515b | 312 | #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED |
bbed653c RM |
313 | /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant |
314 | digit first. Returns a pointer to static storage overwritten by the | |
315 | next call. */ | |
316 | extern char *l64a __P ((long int __n)); | |
317 | ||
036cc82f RM |
318 | /* Read a number from a string S in base 64 as above. */ |
319 | extern long int a64l __P ((__const char *__s)); | |
28f540f4 | 320 | |
b20e47cb | 321 | |
dfd2257a | 322 | # include <sys/types.h> /* we need int32_t... */ |
b20e47cb | 323 | |
28f540f4 RM |
324 | /* These are the functions that actually do things. The `random', `srandom', |
325 | `initstate' and `setstate' functions are those from BSD Unices. | |
326 | The `rand' and `srand' functions are required by the ANSI standard. | |
327 | We provide both interfaces to the same random number generator. */ | |
328 | /* Return a random long integer between 0 and RAND_MAX inclusive. */ | |
b20e47cb | 329 | extern int32_t __random __P ((void)); |
9ebb936d RM |
330 | extern int32_t random __P ((void)); |
331 | ||
28f540f4 RM |
332 | /* Seed the random number generator with the given number. */ |
333 | extern void __srandom __P ((unsigned int __seed)); | |
9ebb936d | 334 | extern void srandom __P ((unsigned int __seed)); |
28f540f4 RM |
335 | |
336 | /* Initialize the random number generator to use state buffer STATEBUF, | |
337 | of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16, | |
338 | 32, 64, 128 and 256, the bigger the better; values less than 8 will | |
339 | cause an error and values greater than 256 will be rounded down. */ | |
340 | extern __ptr_t __initstate __P ((unsigned int __seed, __ptr_t __statebuf, | |
341 | size_t __statelen)); | |
9ebb936d RM |
342 | extern __ptr_t initstate __P ((unsigned int __seed, __ptr_t __statebuf, |
343 | size_t __statelen)); | |
344 | ||
28f540f4 RM |
345 | /* Switch the random number generator to state buffer STATEBUF, |
346 | which should have been previously initialized by `initstate'. */ | |
347 | extern __ptr_t __setstate __P ((__ptr_t __statebuf)); | |
28f540f4 RM |
348 | extern __ptr_t setstate __P ((__ptr_t __statebuf)); |
349 | ||
60478656 | 350 | |
2604afb1 | 351 | # ifdef __USE_MISC |
60478656 RM |
352 | /* Reentrant versions of the `random' family of functions. |
353 | These functions all use the following data structure to contain | |
354 | state, rather than global state variables. */ | |
355 | ||
356 | struct random_data | |
357 | { | |
b20e47cb RM |
358 | int32_t *fptr; /* Front pointer. */ |
359 | int32_t *rptr; /* Rear pointer. */ | |
360 | int32_t *state; /* Array of state values. */ | |
60478656 RM |
361 | int rand_type; /* Type of random number generator. */ |
362 | int rand_deg; /* Degree of random number generator. */ | |
363 | int rand_sep; /* Distance between front and rear. */ | |
b20e47cb | 364 | int32_t *end_ptr; /* Pointer behind state table. */ |
60478656 RM |
365 | }; |
366 | ||
b20e47cb RM |
367 | extern int __random_r __P ((struct random_data *__buf, int32_t *__result)); |
368 | extern int random_r __P ((struct random_data *__buf, int32_t *__result)); | |
8a523922 | 369 | |
60478656 | 370 | extern int __srandom_r __P ((unsigned int __seed, struct random_data *__buf)); |
8a523922 UD |
371 | extern int srandom_r __P ((unsigned int __seed, struct random_data *__buf)); |
372 | ||
60478656 RM |
373 | extern int __initstate_r __P ((unsigned int __seed, __ptr_t __statebuf, |
374 | size_t __statelen, struct random_data *__buf)); | |
60478656 RM |
375 | extern int initstate_r __P ((unsigned int __seed, __ptr_t __statebuf, |
376 | size_t __statelen, struct random_data *__buf)); | |
8a523922 UD |
377 | |
378 | extern int __setstate_r __P ((__ptr_t __statebuf, struct random_data *__buf)); | |
60478656 | 379 | extern int setstate_r __P ((__ptr_t __statebuf, struct random_data *__buf)); |
2604afb1 | 380 | # endif /* Use misc. */ |
19361cb7 | 381 | #endif /* Use SVID || extended X/Open. */ |
60478656 RM |
382 | |
383 | ||
2c6fe0bd UD |
384 | /* Return a random integer between 0 and RAND_MAX inclusive. */ |
385 | extern int rand __P ((void)); | |
386 | /* Seed the random number generator with the given number. */ | |
387 | extern void srand __P ((unsigned int __seed)); | |
388 | ||
19361cb7 | 389 | #ifdef __USE_MISC |
47707456 UD |
390 | /* Reentrant interface according to POSIX.1. */ |
391 | extern int __rand_r __P ((unsigned int *__seed)); | |
392 | extern int rand_r __P ((unsigned int *__seed)); | |
393 | #endif | |
394 | ||
2c6fe0bd | 395 | |
377a515b | 396 | #if defined __USE_SVID || defined __USE_XOPEN |
60478656 RM |
397 | /* System V style 48-bit random number generator functions. */ |
398 | ||
2c6fe0bd UD |
399 | /* Return non-negative, double-precision floating-point value in [0.0,1.0). */ |
400 | extern double drand48 __P ((void)); | |
401 | extern double erand48 __P ((unsigned short int __xsubi[3])); | |
402 | ||
403 | /* Return non-negative, long integer in [0,2^31). */ | |
b4012b75 UD |
404 | extern long int lrand48 __P ((void)); |
405 | extern long int nrand48 __P ((unsigned short int __xsubi[3])); | |
2c6fe0bd UD |
406 | |
407 | /* Return signed, long integers in [-2^31,2^31). */ | |
b4012b75 UD |
408 | extern long int mrand48 __P ((void)); |
409 | extern long int jrand48 __P ((unsigned short int __xsubi[3])); | |
2c6fe0bd UD |
410 | |
411 | /* Seed random number generator. */ | |
b4012b75 | 412 | extern void srand48 __P ((long int __seedval)); |
2c6fe0bd UD |
413 | extern unsigned short int *seed48 __P ((unsigned short int __seed16v[3])); |
414 | extern void lcong48 __P ((unsigned short int __param[7])); | |
415 | ||
60478656 RM |
416 | /* Data structure for communication with thread safe versions. */ |
417 | struct drand48_data | |
418 | { | |
dc30f461 | 419 | unsigned short int x[3]; /* Current state. */ |
60478656 RM |
420 | unsigned short int a[3]; /* Factor in congruential formula. */ |
421 | unsigned short int c; /* Additive const. in congruential formula. */ | |
dc30f461 | 422 | unsigned short int old_x[3]; /* Old state. */ |
60478656 RM |
423 | int init; /* Flag for initializing. */ |
424 | }; | |
425 | ||
dfd2257a | 426 | # ifdef __USE_MISC |
60478656 | 427 | /* Return non-negative, double-precision floating-point value in [0.0,1.0). */ |
60478656 | 428 | extern int drand48_r __P ((struct drand48_data *__buffer, double *__result)); |
47f13fd4 UD |
429 | extern int __erand48_r __P ((unsigned short int __xsubi[3], |
430 | struct drand48_data *__buffer, double *__result)); | |
60478656 RM |
431 | extern int erand48_r __P ((unsigned short int __xsubi[3], |
432 | struct drand48_data *__buffer, double *__result)); | |
2c6fe0bd | 433 | |
60478656 | 434 | /* Return non-negative, long integer in [0,2^31). */ |
b4012b75 | 435 | extern int lrand48_r __P ((struct drand48_data *__buffer, long int *__result)); |
47f13fd4 UD |
436 | extern int __nrand48_r __P ((unsigned short int __xsubi[3], |
437 | struct drand48_data *__buffer, | |
438 | long int *__result)); | |
60478656 | 439 | extern int nrand48_r __P ((unsigned short int __xsubi[3], |
b4012b75 | 440 | struct drand48_data *__buffer, long int *__result)); |
2c6fe0bd | 441 | |
60478656 | 442 | /* Return signed, long integers in [-2^31,2^31). */ |
b4012b75 | 443 | extern int mrand48_r __P ((struct drand48_data *__buffer, long int *__result)); |
47f13fd4 UD |
444 | extern int __jrand48_r __P ((unsigned short int __xsubi[3], |
445 | struct drand48_data *__buffer, | |
446 | long int *__result)); | |
60478656 | 447 | extern int jrand48_r __P ((unsigned short int __xsubi[3], |
b4012b75 | 448 | struct drand48_data *__buffer, long int *__result)); |
2c6fe0bd | 449 | |
60478656 | 450 | /* Seed random number generator. */ |
47f13fd4 UD |
451 | extern int __srand48_r __P ((long int __seedval, |
452 | struct drand48_data *__buffer)); | |
b4012b75 | 453 | extern int srand48_r __P ((long int __seedval, struct drand48_data *__buffer)); |
47f13fd4 UD |
454 | |
455 | extern int __seed48_r __P ((unsigned short int __seed16v[3], | |
456 | struct drand48_data *__buffer)); | |
60478656 RM |
457 | extern int seed48_r __P ((unsigned short int __seed16v[3], |
458 | struct drand48_data *__buffer)); | |
47f13fd4 UD |
459 | |
460 | extern int __lcong48_r __P ((unsigned short int __param[7], | |
461 | struct drand48_data *__buffer)); | |
60478656 RM |
462 | extern int lcong48_r __P ((unsigned short int __param[7], |
463 | struct drand48_data *__buffer)); | |
dfd2257a | 464 | # endif /* Use misc. */ |
60478656 RM |
465 | |
466 | /* Internal function to compute next state of the generator. */ | |
467 | extern int __drand48_iterate __P ((unsigned short int __xsubi[3], | |
468 | struct drand48_data *__buffer)); | |
2c6fe0bd | 469 | #endif /* Use SVID or X/Open. */ |
28f540f4 RM |
470 | |
471 | ||
472 | /* Allocate SIZE bytes of memory. */ | |
473 | extern __ptr_t malloc __P ((size_t __size)); | |
474 | /* Re-allocate the previously allocated block | |
475 | in __ptr_t, making the new block SIZE bytes long. */ | |
476 | extern __ptr_t realloc __P ((__ptr_t __ptr, size_t __size)); | |
477 | /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ | |
478 | extern __ptr_t calloc __P ((size_t __nmemb, size_t __size)); | |
479 | /* Free a block allocated by `malloc', `realloc' or `calloc'. */ | |
480 | extern void free __P ((__ptr_t __ptr)); | |
481 | ||
482 | #ifdef __USE_MISC | |
483 | /* Free a block. An alias for `free'. (Sun Unices). */ | |
484 | extern void cfree __P ((__ptr_t __ptr)); | |
485 | #endif /* Use misc. */ | |
486 | ||
377a515b | 487 | #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC |
2604afb1 | 488 | # include <alloca.h> |
28f540f4 RM |
489 | #endif /* Use GNU, BSD, or misc. */ |
490 | ||
377a515b | 491 | #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED |
28f540f4 RM |
492 | /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */ |
493 | extern __ptr_t valloc __P ((size_t __size)); | |
494 | #endif | |
495 | ||
496 | ||
497 | /* Abort execution and generate a core-dump. */ | |
498 | extern void abort __P ((void)) __attribute__ ((__noreturn__)); | |
499 | ||
500 | ||
501 | /* Register a function to be called when `exit' is called. */ | |
502 | extern int atexit __P ((void (*__func) (void))); | |
503 | ||
504 | #ifdef __USE_MISC | |
505 | /* Register a function to be called with the status | |
506 | given to `exit' and the given argument. */ | |
10dc2a90 UD |
507 | extern int __on_exit __P ((void (*__func) (int __status, __ptr_t __arg), |
508 | __ptr_t __arg)); | |
28f540f4 RM |
509 | extern int on_exit __P ((void (*__func) (int __status, __ptr_t __arg), |
510 | __ptr_t __arg)); | |
511 | #endif | |
512 | ||
513 | /* Call all functions registered with `atexit' and `on_exit', | |
514 | in the reverse of the order in which they were registered | |
515 | perform stdio cleanup, and terminate program execution with STATUS. */ | |
516 | extern void exit __P ((int __status)) __attribute__ ((__noreturn__)); | |
517 | ||
518 | ||
519 | /* Return the value of envariable NAME, or NULL if it doesn't exist. */ | |
520 | extern char *getenv __P ((__const char *__name)); | |
521 | ||
d68171ed UD |
522 | /* This function is similar to the above but returns NULL if the |
523 | programs is running with SUID or SGID enabled. */ | |
524 | extern char *__secure_getenv __P ((__const char *__name)); | |
525 | ||
377a515b | 526 | #if defined __USE_SVID || defined __USE_XOPEN |
28f540f4 RM |
527 | /* The SVID says this is in <stdio.h>, but this seems a better place. */ |
528 | /* Put STRING, which is of the form "NAME=VALUE", in the environment. | |
529 | If there is no `=', remove NAME from the environment. */ | |
530 | extern int putenv __P ((__const char *__string)); | |
531 | #endif | |
532 | ||
533 | #ifdef __USE_BSD | |
534 | /* Set NAME to VALUE in the environment. | |
535 | If REPLACE is nonzero, overwrite an existing value. */ | |
536 | extern int setenv __P ((__const char *__name, __const char *__value, | |
537 | int __replace)); | |
196980f5 RM |
538 | |
539 | /* Remove the variable NAME from the environment. */ | |
540 | extern void unsetenv __P ((__const char *__name)); | |
28f540f4 RM |
541 | #endif |
542 | ||
f0e44959 UD |
543 | #ifdef __USE_MISC |
544 | /* The `clearenv' was planned to be added to POSIX.1 but probably | |
545 | never made it. Nevertheless the POSIX.9 standard (POSIX bindings | |
546 | for Fortran 77) requires this function. */ | |
22d57dd3 | 547 | extern int __clearenv __P ((void)); |
f0e44959 UD |
548 | extern int clearenv __P ((void)); |
549 | #endif | |
550 | ||
2c6fe0bd | 551 | |
377a515b | 552 | #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED |
2c6fe0bd UD |
553 | /* Generate a unique temporary file name from TEMPLATE. |
554 | The last six characters of TEMPLATE must be "XXXXXX"; | |
555 | they are replaced with a string that makes the file name unique. | |
556 | Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */ | |
557 | extern char *mktemp __P ((char *__template)); | |
558 | ||
559 | /* Generate a unique temporary file name from TEMPLATE. | |
560 | The last six characters of TEMPLATE must be "XXXXXX"; | |
561 | they are replaced with a string that makes the filename unique. | |
562 | Returns a file descriptor open on the file for reading and writing, | |
563 | or -1 if it cannot create a uniquely-named file. */ | |
564 | extern int mkstemp __P ((char *__template)); | |
565 | #endif | |
566 | ||
567 | ||
28f540f4 RM |
568 | /* Execute the given line as a shell command. */ |
569 | extern int system __P ((__const char *__command)); | |
570 | ||
571 | ||
fa0bc87c RM |
572 | #ifdef __USE_GNU |
573 | /* Return a malloc'd string containing the canonical absolute name of the | |
574 | named file. The last file name component need not exist, and may be a | |
575 | symlink to a nonexistent file. */ | |
576 | extern char *canonicalize_file_name __P ((__const char *__name)); | |
577 | #endif | |
578 | ||
377a515b | 579 | #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED |
fa0bc87c RM |
580 | /* Return the canonical absolute name of file NAME. The last file name |
581 | component need not exist, and may be a symlink to a nonexistent file. | |
582 | If RESOLVED is null, the result is malloc'd; otherwise, if the canonical | |
583 | name is PATH_MAX chars or more, returns null with `errno' set to | |
584 | ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the | |
585 | name in RESOLVED. */ | |
586 | extern char *realpath __P ((__const char *__name, char *__resolved)); | |
587 | #endif | |
588 | ||
589 | ||
28f540f4 | 590 | /* Shorthand for type of comparison functions. */ |
60478656 | 591 | #ifndef __COMPAR_FN_T |
2604afb1 | 592 | # define __COMPAR_FN_T |
28f540f4 RM |
593 | typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t)); |
594 | ||
2604afb1 | 595 | # ifdef __USE_GNU |
28f540f4 | 596 | typedef __compar_fn_t comparison_fn_t; |
2604afb1 | 597 | # endif |
28f540f4 RM |
598 | #endif |
599 | ||
600 | /* Do a binary search for KEY in BASE, which consists of NMEMB elements | |
601 | of SIZE bytes each, using COMPAR to perform the comparisons. */ | |
602 | extern __ptr_t bsearch __P ((__const __ptr_t __key, __const __ptr_t __base, | |
603 | size_t __nmemb, size_t __size, | |
604 | __compar_fn_t __compar)); | |
605 | ||
606 | /* Sort NMEMB elements of BASE, of SIZE bytes each, | |
607 | using COMPAR to perform the comparisons. */ | |
608 | extern void qsort __P ((__ptr_t __base, size_t __nmemb, size_t __size, | |
609 | __compar_fn_t __compar)); | |
610 | ||
611 | ||
28f540f4 | 612 | /* Return the absolute value of X. */ |
7176f4e4 RM |
613 | extern int abs __P ((int __x)) __attribute__ ((__const__)); |
614 | extern long int labs __P ((long int __x)) __attribute__ ((__const__)); | |
2604afb1 | 615 | #ifdef __USE_ISOC9X |
2f6d1f1b UD |
616 | extern long long int llabs __P ((long long int __x)) |
617 | __attribute__ ((__const__)); | |
59dd8641 | 618 | #endif |
28f540f4 RM |
619 | |
620 | ||
59dd8641 | 621 | /* Return the `div_t', `ldiv_t' or `lldiv_t' representation |
28f540f4 RM |
622 | of the value of NUMER over DENOM. */ |
623 | /* GCC may have built-ins for these someday. */ | |
7176f4e4 | 624 | extern div_t div __P ((int __numer, int __denom)) __attribute__ ((__const__)); |
2f6d1f1b UD |
625 | extern ldiv_t ldiv __P ((long int __numer, long int __denom)) |
626 | __attribute__ ((__const__)); | |
627 | #ifdef __USE_ISOC9X | |
628 | extern lldiv_t lldiv __P ((long long int __numer, long long int __denom)) | |
629 | __attribute__ ((__const__)); | |
59dd8641 | 630 | #endif |
28f540f4 RM |
631 | |
632 | ||
377a515b | 633 | #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED |
60478656 RM |
634 | /* Convert floating point numbers to strings. The returned values are |
635 | valid only until another call to the same function. */ | |
636 | ||
637 | /* Convert VALUE to a string with NDIGIT digits and return a pointer to | |
638 | this. Set *DECPT with the position of the decimal character and *SIGN | |
639 | with the sign of the number. */ | |
2c6fe0bd UD |
640 | extern char *ecvt __P ((double __value, int __ndigit, int *__decpt, |
641 | int *__sign)); | |
60478656 RM |
642 | |
643 | /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT | |
644 | with the position of the decimal character and *SIGN with the sign of | |
645 | the number. */ | |
2c6fe0bd UD |
646 | extern char *fcvt __P ((double __value, int __ndigit, int *__decpt, |
647 | int *__sign)); | |
60478656 RM |
648 | |
649 | /* If possible convert VALUE to a string with NDIGIT significant digits. | |
650 | Otherwise use exponential representation. The resulting string will | |
651 | be written to BUF. */ | |
2c6fe0bd | 652 | extern char *gcvt __P ((double __value, int __ndigit, char *__buf)); |
60478656 | 653 | |
2064087b | 654 | /* Long double versions of above functions. */ |
2c6fe0bd UD |
655 | extern char *qecvt __P ((__long_double_t __value, int __ndigit, int *__decpt, |
656 | int *__sign)); | |
657 | extern char *qfcvt __P ((__long_double_t __value, int __ndigit, int *__decpt, | |
658 | int *__sign)); | |
659 | extern char *qgcvt __P ((__long_double_t __value, int __ndigit, char *__buf)); | |
2064087b RM |
660 | |
661 | ||
dfd2257a | 662 | # ifdef __USE_MISC |
60478656 RM |
663 | /* Reentrant version of the functions above which provide their own |
664 | buffers. */ | |
2c6fe0bd UD |
665 | extern int ecvt_r __P ((double __value, int __ndigit, int *__decpt, |
666 | int *__sign, char *__buf, size_t __len)); | |
667 | extern int fcvt_r __P ((double __value, int __ndigit, int *__decpt, | |
668 | int *__sign, char *__buf, size_t __len)); | |
669 | ||
670 | extern int qecvt_r __P ((__long_double_t __value, int __ndigit, int *__decpt, | |
671 | int *__sign, char *__buf, size_t __len)); | |
672 | extern int qfcvt_r __P ((__long_double_t __value, int __ndigit, int *__decpt, | |
673 | int *__sign, char *__buf, size_t __len)); | |
dfd2257a | 674 | # endif /* misc */ |
2c6fe0bd | 675 | #endif /* use MISC || use X/Open Unix */ |
60478656 RM |
676 | |
677 | ||
28f540f4 RM |
678 | /* Return the length of the multibyte character |
679 | in S, which is no longer than N. */ | |
680 | extern int mblen __P ((__const char *__s, size_t __n)); | |
681 | /* Return the length of the given multibyte character, | |
682 | putting its `wchar_t' representation in *PWC. */ | |
2f6d1f1b UD |
683 | extern int mbtowc __P ((wchar_t *__restrict __pwc, |
684 | __const char *__restrict __s, size_t __n)); | |
28f540f4 RM |
685 | /* Put the multibyte character represented |
686 | by WCHAR in S, returning its length. */ | |
687 | extern int wctomb __P ((char *__s, wchar_t __wchar)); | |
688 | ||
28f540f4 RM |
689 | |
690 | /* Convert a multibyte string to a wide char string. */ | |
2f6d1f1b UD |
691 | extern size_t mbstowcs __P ((wchar_t *__restrict __pwcs, |
692 | __const char *__restrict __s, size_t __n)); | |
28f540f4 | 693 | /* Convert a wide char string to multibyte string. */ |
2f6d1f1b UD |
694 | extern size_t wcstombs __P ((char *__restrict __s, |
695 | __const wchar_t *__restrict __pwcs, size_t __n)); | |
28f540f4 RM |
696 | |
697 | ||
857fa1b8 RM |
698 | #ifdef __USE_SVID |
699 | /* Determine whether the string value of RESPONSE matches the affirmation | |
700 | or negative response expression as specified by the LC_MESSAGES category | |
701 | in the program's current locale. Returns 1 if affirmative, 0 if | |
702 | negative, and -1 if not matching. */ | |
703 | extern int rpmatch __P ((__const char *__response)); | |
704 | #endif | |
705 | ||
706 | ||
2c6fe0bd | 707 | #ifdef __USE_XOPEN_EXTENDED |
2064087b RM |
708 | /* Parse comma separated suboption from *OPTIONP and match against |
709 | strings in TOKENS. If found return index and set *VALUEP to | |
710 | optional value introduced by an equal sign. If the suboption is | |
711 | not part of TOKENS return in *VALUEP beginning of unknown | |
712 | suboption. On exit *OPTIONP is set to the beginning of the next | |
2604afb1 | 713 | token or at the terminating NUL character. */ |
2064087b RM |
714 | extern int getsubopt __P ((char **__optionp, __const char *__const *__tokens, |
715 | char **__valuep)); | |
716 | #endif | |
717 | ||
718 | ||
2c6fe0bd UD |
719 | #ifdef __USE_XOPEN |
720 | ||
721 | /* Setup DES tables according KEY. */ | |
722 | extern void setkey __P ((__const char *__key)); | |
6591c335 UD |
723 | |
724 | /* X/Open pseudo terminal handling. */ | |
725 | ||
726 | /* The next four functions all take a master pseudo-tty fd and | |
727 | perform an operation on the associated slave: */ | |
728 | ||
729 | /* Chown the slave to the calling user. */ | |
730 | extern int grantpt __P ((int __fd)); | |
731 | ||
732 | /* Release an internal lock so the slave can be opened. | |
733 | Call after grantpt(). */ | |
734 | extern int unlockpt __P ((int __fd)); | |
735 | ||
736 | /* Get the name of the slave. */ | |
737 | extern char *ptsname __P ((int __fd)); | |
2c6fe0bd UD |
738 | #endif |
739 | ||
6591c335 UD |
740 | #ifdef __USE_GNU |
741 | /* Reentrant version of ptsname. */ | |
742 | extern char *__ptsname_r __P ((int __fd, char *__buf, unsigned int __len)); | |
743 | extern char *ptsname_r __P ((int __fd, char *__buf, unsigned int __len)); | |
744 | ||
745 | /* Open a master pseudo tty and return its file descriptor. */ | |
746 | extern int __getpt __P ((void)); | |
747 | extern int getpt __P ((void)); | |
748 | #endif | |
2c6fe0bd | 749 | |
28f540f4 RM |
750 | __END_DECLS |
751 | ||
752 | #endif /* stdlib.h */ |