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