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