]>
Commit | Line | Data |
---|---|---|
19361cb7 | 1 | /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 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 | /* | |
ba1ffaa1 | 20 | * ISO S Standard: 4.10 GENERAL UTILITIES <stdlib.h> |
28f540f4 RM |
21 | */ |
22 | ||
23 | #ifndef _STDLIB_H | |
24 | ||
25 | #define _STDLIB_H 1 | |
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 | ||
59dd8641 RM |
50 | #ifdef __USE_GNU |
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 | ||
7cc27f44 UD |
82 | #if defined (__GNUC__) && defined (__USE_MISC) |
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 RM |
87 | /* Convert a string to a floating-point number. */ |
88 | extern double strtod __P ((__const char *__nptr, char **__endptr)); | |
89 | ||
90 | #ifdef __USE_GNU | |
91 | /* Likewise for `float' and `long double' sizes of floating-point numbers. */ | |
28f540f4 | 92 | extern float strtof __P ((__const char *__nptr, char **__endptr)); |
28f540f4 RM |
93 | extern __long_double_t strtold __P ((__const char *__nptr, char **__endptr)); |
94 | #endif | |
95 | ||
96 | /* Convert a string to a long integer. */ | |
97 | extern long int strtol __P ((__const char *__nptr, char **__endptr, | |
98 | int __base)); | |
99 | /* Convert a string to an unsigned long integer. */ | |
100 | extern unsigned long int strtoul __P ((__const char *__nptr, | |
101 | char **__endptr, int __base)); | |
102 | ||
103 | #if defined (__GNUC__) && defined (__USE_BSD) | |
104 | /* Convert a string to a quadword integer. */ | |
105 | extern long long int strtoq __P ((__const char *__nptr, char **__endptr, | |
106 | int __base)); | |
107 | /* Convert a string to an unsigned quadword integer. */ | |
108 | extern unsigned long long int strtouq __P ((__const char *__nptr, | |
109 | char **__endptr, int __base)); | |
110 | #endif /* GCC and use BSD. */ | |
111 | ||
76060ec0 | 112 | #if defined (__GNUC__) && defined (__USE_MISC) |
7cc27f44 UD |
113 | /* These functions will part of the standard C library in ISO C 9X. */ |
114 | ||
76060ec0 RM |
115 | /* Convert a string to a quadword integer. */ |
116 | extern long long int strtoll __P ((__const char *__nptr, char **__endptr, | |
117 | int __base)); | |
118 | /* Convert a string to an unsigned quadword integer. */ | |
119 | extern unsigned long long int strtoull __P ((__const char *__nptr, | |
120 | char **__endptr, int __base)); | |
121 | #endif /* GCC and use MISC. */ | |
122 | ||
123 | ||
f0bf9cb9 RM |
124 | |
125 | /* The internal entry points for `strtoX' take an extra flag argument | |
126 | saying whether or not to parse locale-dependent number grouping. */ | |
127 | ||
75cd5204 RM |
128 | extern double __strtod_internal __P ((__const char *__nptr, |
129 | char **__endptr, int __group)); | |
130 | extern float __strtof_internal __P ((__const char *__nptr, char **__endptr, | |
131 | int __group)); | |
132 | extern __long_double_t __strtold_internal __P ((__const char *__nptr, | |
133 | char **__endptr, int __group)); | |
134 | extern long int __strtol_internal __P ((__const char *__nptr, char **__endptr, | |
135 | int __base, int __group)); | |
136 | extern unsigned long int __strtoul_internal __P ((__const char *__nptr, | |
f0bf9cb9 | 137 | char **__endptr, int __base, |
75cd5204 RM |
138 | int __group)); |
139 | #ifdef __GNUC__ | |
140 | extern long long int __strtoq_internal __P ((__const char *__nptr, | |
141 | char **__endptr, int __base, | |
142 | int __group)); | |
143 | extern unsigned long long int __strtouq_internal __P ((__const char *__nptr, | |
144 | char **__endptr, | |
145 | int __base, | |
146 | int __group)); | |
147 | #endif /* GCC */ | |
f0bf9cb9 | 148 | |
28f540f4 | 149 | #if defined (__OPTIMIZE__) && __GNUC__ >= 2 |
f0bf9cb9 RM |
150 | /* Define inline functions which call the internal entry points. */ |
151 | ||
152 | extern __inline double strtod (__const char *__nptr, char **__endptr) | |
153 | { return __strtod_internal (__nptr, __endptr, 0); } | |
154 | extern __inline long int strtol (__const char *__nptr, | |
155 | char **__endptr, int __base) | |
156 | { return __strtol_internal (__nptr, __endptr, __base, 0); } | |
157 | extern __inline unsigned long int strtoul (__const char *__nptr, | |
158 | char **__endptr, int __base) | |
159 | { return __strtoul_internal (__nptr, __endptr, __base, 0); } | |
160 | ||
161 | #ifdef __USE_GNU | |
162 | extern __inline float strtof (__const char *__nptr, char **__endptr) | |
163 | { return __strtof_internal (__nptr, __endptr, 0); } | |
164 | extern __inline __long_double_t strtold (__const char *__nptr, char **__endptr) | |
165 | { return __strtold_internal (__nptr, __endptr, 0); } | |
166 | #endif | |
167 | ||
168 | #ifdef __USE_BSD | |
169 | extern __inline long long int strtoq (__const char *__nptr, char **__endptr, | |
170 | int __base) | |
171 | { return __strtoq_internal (__nptr, __endptr, __base, 0); } | |
172 | extern __inline unsigned long long int strtouq (__const char *__nptr, | |
75cd5204 | 173 | char **__endptr, int __base) |
f0bf9cb9 RM |
174 | { return __strtouq_internal (__nptr, __endptr, __base, 0); } |
175 | #endif | |
176 | ||
76060ec0 RM |
177 | #ifdef __USE_MISC |
178 | extern __inline long long int strtoll (__const char *__nptr, char **__endptr, | |
179 | int __base) | |
180 | { return __strtoq_internal (__nptr, __endptr, __base, 0); } | |
181 | extern __inline unsigned long long int strtoull (__const char *__nptr, | |
182 | char **__endptr, int __base) | |
183 | { return __strtouq_internal (__nptr, __endptr, __base, 0); } | |
184 | #endif | |
185 | ||
28f540f4 | 186 | extern __inline double atof (__const char *__nptr) |
f0bf9cb9 | 187 | { return strtod (__nptr, (char **) NULL); } |
28f540f4 RM |
188 | extern __inline int atoi (__const char *__nptr) |
189 | { return (int) strtol (__nptr, (char **) NULL, 10); } | |
190 | extern __inline long int atol (__const char *__nptr) | |
191 | { return strtol (__nptr, (char **) NULL, 10); } | |
7cc27f44 UD |
192 | |
193 | #ifdef __USE_MISC | |
194 | extern __inline long long int atoll (__const char *__nptr) | |
195 | { return strtoll (__nptr, (char **) NULL, 10); } | |
196 | #endif | |
28f540f4 RM |
197 | #endif /* Optimizing GCC >=2. */ |
198 | ||
199 | ||
2c6fe0bd | 200 | #if defined(__USE_SVID) || defined(__USE_XOPEN_EXTENDED) |
bbed653c RM |
201 | /* Convert N to base 64 using the digits "./0-9A-Za-z", least-significant |
202 | digit first. Returns a pointer to static storage overwritten by the | |
203 | next call. */ | |
204 | extern char *l64a __P ((long int __n)); | |
205 | ||
036cc82f RM |
206 | /* Read a number from a string S in base 64 as above. */ |
207 | extern long int a64l __P ((__const char *__s)); | |
28f540f4 | 208 | |
b20e47cb RM |
209 | |
210 | #include <sys/types.h> /* we need int32_t... */ | |
211 | ||
28f540f4 RM |
212 | /* These are the functions that actually do things. The `random', `srandom', |
213 | `initstate' and `setstate' functions are those from BSD Unices. | |
214 | The `rand' and `srand' functions are required by the ANSI standard. | |
215 | We provide both interfaces to the same random number generator. */ | |
216 | /* Return a random long integer between 0 and RAND_MAX inclusive. */ | |
b20e47cb | 217 | extern int32_t __random __P ((void)); |
9ebb936d RM |
218 | extern int32_t random __P ((void)); |
219 | ||
28f540f4 RM |
220 | /* Seed the random number generator with the given number. */ |
221 | extern void __srandom __P ((unsigned int __seed)); | |
9ebb936d | 222 | extern void srandom __P ((unsigned int __seed)); |
28f540f4 RM |
223 | |
224 | /* Initialize the random number generator to use state buffer STATEBUF, | |
225 | of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16, | |
226 | 32, 64, 128 and 256, the bigger the better; values less than 8 will | |
227 | cause an error and values greater than 256 will be rounded down. */ | |
228 | extern __ptr_t __initstate __P ((unsigned int __seed, __ptr_t __statebuf, | |
229 | size_t __statelen)); | |
9ebb936d RM |
230 | extern __ptr_t initstate __P ((unsigned int __seed, __ptr_t __statebuf, |
231 | size_t __statelen)); | |
232 | ||
28f540f4 RM |
233 | /* Switch the random number generator to state buffer STATEBUF, |
234 | which should have been previously initialized by `initstate'. */ | |
235 | extern __ptr_t __setstate __P ((__ptr_t __statebuf)); | |
28f540f4 RM |
236 | extern __ptr_t setstate __P ((__ptr_t __statebuf)); |
237 | ||
60478656 | 238 | |
19361cb7 | 239 | #ifdef __USE_MISC |
60478656 RM |
240 | /* Reentrant versions of the `random' family of functions. |
241 | These functions all use the following data structure to contain | |
242 | state, rather than global state variables. */ | |
243 | ||
244 | struct random_data | |
245 | { | |
b20e47cb RM |
246 | int32_t *fptr; /* Front pointer. */ |
247 | int32_t *rptr; /* Rear pointer. */ | |
248 | int32_t *state; /* Array of state values. */ | |
60478656 RM |
249 | int rand_type; /* Type of random number generator. */ |
250 | int rand_deg; /* Degree of random number generator. */ | |
251 | int rand_sep; /* Distance between front and rear. */ | |
b20e47cb | 252 | int32_t *end_ptr; /* Pointer behind state table. */ |
60478656 RM |
253 | }; |
254 | ||
b20e47cb RM |
255 | extern int __random_r __P ((struct random_data *__buf, int32_t *__result)); |
256 | extern int random_r __P ((struct random_data *__buf, int32_t *__result)); | |
8a523922 | 257 | |
60478656 | 258 | extern int __srandom_r __P ((unsigned int __seed, struct random_data *__buf)); |
8a523922 UD |
259 | extern int srandom_r __P ((unsigned int __seed, struct random_data *__buf)); |
260 | ||
60478656 RM |
261 | extern int __initstate_r __P ((unsigned int __seed, __ptr_t __statebuf, |
262 | size_t __statelen, struct random_data *__buf)); | |
60478656 RM |
263 | extern int initstate_r __P ((unsigned int __seed, __ptr_t __statebuf, |
264 | size_t __statelen, struct random_data *__buf)); | |
8a523922 UD |
265 | |
266 | extern int __setstate_r __P ((__ptr_t __statebuf, struct random_data *__buf)); | |
60478656 | 267 | extern int setstate_r __P ((__ptr_t __statebuf, struct random_data *__buf)); |
19361cb7 UD |
268 | #endif /* Use misc. */ |
269 | #endif /* Use SVID || extended X/Open. */ | |
60478656 RM |
270 | |
271 | ||
2c6fe0bd UD |
272 | /* Return a random integer between 0 and RAND_MAX inclusive. */ |
273 | extern int rand __P ((void)); | |
274 | /* Seed the random number generator with the given number. */ | |
275 | extern void srand __P ((unsigned int __seed)); | |
276 | ||
19361cb7 | 277 | #ifdef __USE_MISC |
47707456 UD |
278 | /* Reentrant interface according to POSIX.1. */ |
279 | extern int __rand_r __P ((unsigned int *__seed)); | |
280 | extern int rand_r __P ((unsigned int *__seed)); | |
281 | #endif | |
282 | ||
2c6fe0bd UD |
283 | |
284 | #if defined(__USE_SVID) || defined(__USE_XOPEN) | |
60478656 RM |
285 | /* System V style 48-bit random number generator functions. */ |
286 | ||
2c6fe0bd UD |
287 | /* Return non-negative, double-precision floating-point value in [0.0,1.0). */ |
288 | extern double drand48 __P ((void)); | |
289 | extern double erand48 __P ((unsigned short int __xsubi[3])); | |
290 | ||
291 | /* Return non-negative, long integer in [0,2^31). */ | |
292 | extern long lrand48 __P ((void)); | |
293 | extern long nrand48 __P ((unsigned short int __xsubi[3])); | |
294 | ||
295 | /* Return signed, long integers in [-2^31,2^31). */ | |
296 | extern long mrand48 __P ((void)); | |
297 | extern long jrand48 __P ((unsigned short int __xsubi[3])); | |
298 | ||
299 | /* Seed random number generator. */ | |
300 | extern void srand48 __P ((long __seedval)); | |
301 | extern unsigned short int *seed48 __P ((unsigned short int __seed16v[3])); | |
302 | extern void lcong48 __P ((unsigned short int __param[7])); | |
303 | ||
60478656 RM |
304 | /* Data structure for communication with thread safe versions. */ |
305 | struct drand48_data | |
306 | { | |
307 | unsigned short int X[3]; /* Current state. */ | |
308 | unsigned short int a[3]; /* Factor in congruential formula. */ | |
309 | unsigned short int c; /* Additive const. in congruential formula. */ | |
310 | unsigned short int old_X[3]; /* Old state. */ | |
311 | int init; /* Flag for initializing. */ | |
312 | }; | |
313 | ||
19361cb7 | 314 | #ifdef __USE_MISC |
60478656 | 315 | /* Return non-negative, double-precision floating-point value in [0.0,1.0). */ |
60478656 | 316 | extern int drand48_r __P ((struct drand48_data *__buffer, double *__result)); |
60478656 RM |
317 | extern int erand48_r __P ((unsigned short int __xsubi[3], |
318 | struct drand48_data *__buffer, double *__result)); | |
2c6fe0bd | 319 | |
60478656 | 320 | /* Return non-negative, long integer in [0,2^31). */ |
60478656 | 321 | extern int lrand48_r __P ((struct drand48_data *__buffer, long *__result)); |
60478656 RM |
322 | extern int nrand48_r __P ((unsigned short int __xsubi[3], |
323 | struct drand48_data *__buffer, long *__result)); | |
2c6fe0bd | 324 | |
60478656 | 325 | /* Return signed, long integers in [-2^31,2^31). */ |
60478656 | 326 | extern int mrand48_r __P ((struct drand48_data *__buffer, long *__result)); |
60478656 RM |
327 | extern int jrand48_r __P ((unsigned short int __xsubi[3], |
328 | struct drand48_data *__buffer, long *__result)); | |
2c6fe0bd | 329 | |
60478656 | 330 | /* Seed random number generator. */ |
60478656 | 331 | extern int srand48_r __P ((long __seedval, struct drand48_data *__buffer)); |
60478656 RM |
332 | extern int seed48_r __P ((unsigned short int __seed16v[3], |
333 | struct drand48_data *__buffer)); | |
60478656 RM |
334 | extern int lcong48_r __P ((unsigned short int __param[7], |
335 | struct drand48_data *__buffer)); | |
19361cb7 | 336 | #endif /* Use misc. */ |
60478656 RM |
337 | |
338 | /* Internal function to compute next state of the generator. */ | |
339 | extern int __drand48_iterate __P ((unsigned short int __xsubi[3], | |
340 | struct drand48_data *__buffer)); | |
2c6fe0bd | 341 | #endif /* Use SVID or X/Open. */ |
28f540f4 RM |
342 | |
343 | ||
344 | /* Allocate SIZE bytes of memory. */ | |
345 | extern __ptr_t malloc __P ((size_t __size)); | |
346 | /* Re-allocate the previously allocated block | |
347 | in __ptr_t, making the new block SIZE bytes long. */ | |
348 | extern __ptr_t realloc __P ((__ptr_t __ptr, size_t __size)); | |
349 | /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ | |
350 | extern __ptr_t calloc __P ((size_t __nmemb, size_t __size)); | |
351 | /* Free a block allocated by `malloc', `realloc' or `calloc'. */ | |
352 | extern void free __P ((__ptr_t __ptr)); | |
353 | ||
354 | #ifdef __USE_MISC | |
355 | /* Free a block. An alias for `free'. (Sun Unices). */ | |
356 | extern void cfree __P ((__ptr_t __ptr)); | |
357 | #endif /* Use misc. */ | |
358 | ||
359 | #if defined(__USE_GNU) || defined(__USE_BSD) || defined(__USE_MISC) | |
360 | #include <alloca.h> | |
361 | #endif /* Use GNU, BSD, or misc. */ | |
362 | ||
2c6fe0bd | 363 | #if defined(__USE_BSD) || defined(__USE_XOPEN_EXTENDED) |
28f540f4 RM |
364 | /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */ |
365 | extern __ptr_t valloc __P ((size_t __size)); | |
366 | #endif | |
367 | ||
368 | ||
369 | /* Abort execution and generate a core-dump. */ | |
370 | extern void abort __P ((void)) __attribute__ ((__noreturn__)); | |
371 | ||
372 | ||
373 | /* Register a function to be called when `exit' is called. */ | |
374 | extern int atexit __P ((void (*__func) (void))); | |
375 | ||
376 | #ifdef __USE_MISC | |
377 | /* Register a function to be called with the status | |
378 | given to `exit' and the given argument. */ | |
10dc2a90 UD |
379 | extern int __on_exit __P ((void (*__func) (int __status, __ptr_t __arg), |
380 | __ptr_t __arg)); | |
28f540f4 RM |
381 | extern int on_exit __P ((void (*__func) (int __status, __ptr_t __arg), |
382 | __ptr_t __arg)); | |
383 | #endif | |
384 | ||
385 | /* Call all functions registered with `atexit' and `on_exit', | |
386 | in the reverse of the order in which they were registered | |
387 | perform stdio cleanup, and terminate program execution with STATUS. */ | |
388 | extern void exit __P ((int __status)) __attribute__ ((__noreturn__)); | |
389 | ||
390 | ||
391 | /* Return the value of envariable NAME, or NULL if it doesn't exist. */ | |
392 | extern char *getenv __P ((__const char *__name)); | |
393 | ||
d68171ed UD |
394 | /* This function is similar to the above but returns NULL if the |
395 | programs is running with SUID or SGID enabled. */ | |
396 | extern char *__secure_getenv __P ((__const char *__name)); | |
397 | ||
2c6fe0bd | 398 | #if defined(__USE_SVID) || defined(__USE_XOPEN) |
28f540f4 RM |
399 | /* The SVID says this is in <stdio.h>, but this seems a better place. */ |
400 | /* Put STRING, which is of the form "NAME=VALUE", in the environment. | |
401 | If there is no `=', remove NAME from the environment. */ | |
402 | extern int putenv __P ((__const char *__string)); | |
403 | #endif | |
404 | ||
405 | #ifdef __USE_BSD | |
406 | /* Set NAME to VALUE in the environment. | |
407 | If REPLACE is nonzero, overwrite an existing value. */ | |
408 | extern int setenv __P ((__const char *__name, __const char *__value, | |
409 | int __replace)); | |
196980f5 RM |
410 | |
411 | /* Remove the variable NAME from the environment. */ | |
412 | extern void unsetenv __P ((__const char *__name)); | |
28f540f4 RM |
413 | #endif |
414 | ||
f0e44959 UD |
415 | #ifdef __USE_MISC |
416 | /* The `clearenv' was planned to be added to POSIX.1 but probably | |
417 | never made it. Nevertheless the POSIX.9 standard (POSIX bindings | |
418 | for Fortran 77) requires this function. */ | |
419 | extern int clearenv __P ((void)); | |
420 | #endif | |
421 | ||
2c6fe0bd UD |
422 | |
423 | #if defined(__USE_MISC) || defined(__USE_XOPEN_EXTENDED) | |
424 | /* Generate a unique temporary file name from TEMPLATE. | |
425 | The last six characters of TEMPLATE must be "XXXXXX"; | |
426 | they are replaced with a string that makes the file name unique. | |
427 | Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */ | |
428 | extern char *mktemp __P ((char *__template)); | |
429 | ||
430 | /* Generate a unique temporary file name from TEMPLATE. | |
431 | The last six characters of TEMPLATE must be "XXXXXX"; | |
432 | they are replaced with a string that makes the filename unique. | |
433 | Returns a file descriptor open on the file for reading and writing, | |
434 | or -1 if it cannot create a uniquely-named file. */ | |
435 | extern int mkstemp __P ((char *__template)); | |
436 | #endif | |
437 | ||
438 | ||
28f540f4 RM |
439 | /* Execute the given line as a shell command. */ |
440 | extern int system __P ((__const char *__command)); | |
441 | ||
442 | ||
fa0bc87c RM |
443 | #ifdef __USE_GNU |
444 | /* Return a malloc'd string containing the canonical absolute name of the | |
445 | named file. The last file name component need not exist, and may be a | |
446 | symlink to a nonexistent file. */ | |
447 | extern char *canonicalize_file_name __P ((__const char *__name)); | |
448 | #endif | |
449 | ||
2c6fe0bd | 450 | #if defined(__USE_BSD) || defined(__USE_XOPEN_EXTENDED) |
fa0bc87c RM |
451 | /* Return the canonical absolute name of file NAME. The last file name |
452 | component need not exist, and may be a symlink to a nonexistent file. | |
453 | If RESOLVED is null, the result is malloc'd; otherwise, if the canonical | |
454 | name is PATH_MAX chars or more, returns null with `errno' set to | |
455 | ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the | |
456 | name in RESOLVED. */ | |
457 | extern char *realpath __P ((__const char *__name, char *__resolved)); | |
458 | #endif | |
459 | ||
460 | ||
28f540f4 | 461 | /* Shorthand for type of comparison functions. */ |
60478656 RM |
462 | #ifndef __COMPAR_FN_T |
463 | #define __COMPAR_FN_T | |
28f540f4 | 464 | typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t)); |
60478656 | 465 | #endif |
28f540f4 RM |
466 | |
467 | #ifdef __USE_GNU | |
468 | typedef __compar_fn_t comparison_fn_t; | |
469 | #endif | |
470 | ||
471 | /* Do a binary search for KEY in BASE, which consists of NMEMB elements | |
472 | of SIZE bytes each, using COMPAR to perform the comparisons. */ | |
473 | extern __ptr_t bsearch __P ((__const __ptr_t __key, __const __ptr_t __base, | |
474 | size_t __nmemb, size_t __size, | |
475 | __compar_fn_t __compar)); | |
476 | ||
477 | /* Sort NMEMB elements of BASE, of SIZE bytes each, | |
478 | using COMPAR to perform the comparisons. */ | |
479 | extern void qsort __P ((__ptr_t __base, size_t __nmemb, size_t __size, | |
480 | __compar_fn_t __compar)); | |
481 | ||
482 | ||
28f540f4 | 483 | /* Return the absolute value of X. */ |
7176f4e4 RM |
484 | extern int abs __P ((int __x)) __attribute__ ((__const__)); |
485 | extern long int labs __P ((long int __x)) __attribute__ ((__const__)); | |
59dd8641 RM |
486 | #ifdef __USE_GNU |
487 | extern long long int llabs __P ((long long int __x)) __attribute__ ((__const__)); | |
488 | #endif | |
28f540f4 RM |
489 | |
490 | ||
59dd8641 | 491 | /* Return the `div_t', `ldiv_t' or `lldiv_t' representation |
28f540f4 RM |
492 | of the value of NUMER over DENOM. */ |
493 | /* GCC may have built-ins for these someday. */ | |
7176f4e4 RM |
494 | extern div_t div __P ((int __numer, int __denom)) __attribute__ ((__const__)); |
495 | extern ldiv_t ldiv __P ((long int __numer, long int __denom)) __attribute__ ((__const__)); | |
59dd8641 RM |
496 | #ifdef __USE_GNU |
497 | extern lldiv_t lldiv __P ((long long int __numer, long long int __denom)) __attribute__ ((__const__)); | |
498 | #endif | |
28f540f4 RM |
499 | |
500 | ||
2c6fe0bd | 501 | #if defined(__USE_SVID) || defined(__USE_XOPEN_EXTENDED) |
60478656 RM |
502 | /* Convert floating point numbers to strings. The returned values are |
503 | valid only until another call to the same function. */ | |
504 | ||
505 | /* Convert VALUE to a string with NDIGIT digits and return a pointer to | |
506 | this. Set *DECPT with the position of the decimal character and *SIGN | |
507 | with the sign of the number. */ | |
2c6fe0bd UD |
508 | extern char *ecvt __P ((double __value, int __ndigit, int *__decpt, |
509 | int *__sign)); | |
60478656 RM |
510 | |
511 | /* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT | |
512 | with the position of the decimal character and *SIGN with the sign of | |
513 | the number. */ | |
2c6fe0bd UD |
514 | extern char *fcvt __P ((double __value, int __ndigit, int *__decpt, |
515 | int *__sign)); | |
60478656 RM |
516 | |
517 | /* If possible convert VALUE to a string with NDIGIT significant digits. | |
518 | Otherwise use exponential representation. The resulting string will | |
519 | be written to BUF. */ | |
2c6fe0bd | 520 | extern char *gcvt __P ((double __value, int __ndigit, char *__buf)); |
60478656 | 521 | |
2064087b | 522 | /* Long double versions of above functions. */ |
2c6fe0bd UD |
523 | extern char *qecvt __P ((__long_double_t __value, int __ndigit, int *__decpt, |
524 | int *__sign)); | |
525 | extern char *qfcvt __P ((__long_double_t __value, int __ndigit, int *__decpt, | |
526 | int *__sign)); | |
527 | extern char *qgcvt __P ((__long_double_t __value, int __ndigit, char *__buf)); | |
2064087b RM |
528 | |
529 | ||
19361cb7 | 530 | #ifdef __USE_MISC |
60478656 RM |
531 | /* Reentrant version of the functions above which provide their own |
532 | buffers. */ | |
2c6fe0bd UD |
533 | extern int ecvt_r __P ((double __value, int __ndigit, int *__decpt, |
534 | int *__sign, char *__buf, size_t __len)); | |
535 | extern int fcvt_r __P ((double __value, int __ndigit, int *__decpt, | |
536 | int *__sign, char *__buf, size_t __len)); | |
537 | ||
538 | extern int qecvt_r __P ((__long_double_t __value, int __ndigit, int *__decpt, | |
539 | int *__sign, char *__buf, size_t __len)); | |
540 | extern int qfcvt_r __P ((__long_double_t __value, int __ndigit, int *__decpt, | |
541 | int *__sign, char *__buf, size_t __len)); | |
19361cb7 | 542 | #endif /* misc */ |
2c6fe0bd | 543 | #endif /* use MISC || use X/Open Unix */ |
60478656 RM |
544 | |
545 | ||
28f540f4 RM |
546 | /* Return the length of the multibyte character |
547 | in S, which is no longer than N. */ | |
548 | extern int mblen __P ((__const char *__s, size_t __n)); | |
549 | /* Return the length of the given multibyte character, | |
550 | putting its `wchar_t' representation in *PWC. */ | |
036cc82f | 551 | extern int mbtowc __P ((wchar_t *__pwc, __const char *__s, size_t __n)); |
28f540f4 RM |
552 | /* Put the multibyte character represented |
553 | by WCHAR in S, returning its length. */ | |
554 | extern int wctomb __P ((char *__s, wchar_t __wchar)); | |
555 | ||
556 | #if defined (__OPTIMIZE__) && __GNUC__ >= 2 | |
557 | extern __inline int mblen (__const char *__s, size_t __n) | |
558 | { return mbtowc ((wchar_t *) NULL, __s, __n); } | |
559 | #endif /* Optimizing GCC >=2. */ | |
560 | ||
561 | ||
562 | /* Convert a multibyte string to a wide char string. */ | |
036cc82f | 563 | extern size_t mbstowcs __P ((wchar_t *__pwcs, __const char *__s, size_t __n)); |
28f540f4 | 564 | /* Convert a wide char string to multibyte string. */ |
036cc82f | 565 | extern size_t wcstombs __P ((char *__s, __const wchar_t *__pwcs, size_t __n)); |
28f540f4 RM |
566 | |
567 | ||
857fa1b8 RM |
568 | #ifdef __USE_SVID |
569 | /* Determine whether the string value of RESPONSE matches the affirmation | |
570 | or negative response expression as specified by the LC_MESSAGES category | |
571 | in the program's current locale. Returns 1 if affirmative, 0 if | |
572 | negative, and -1 if not matching. */ | |
573 | extern int rpmatch __P ((__const char *__response)); | |
574 | #endif | |
575 | ||
576 | ||
2c6fe0bd | 577 | #ifdef __USE_XOPEN_EXTENDED |
2064087b RM |
578 | /* Parse comma separated suboption from *OPTIONP and match against |
579 | strings in TOKENS. If found return index and set *VALUEP to | |
580 | optional value introduced by an equal sign. If the suboption is | |
581 | not part of TOKENS return in *VALUEP beginning of unknown | |
582 | suboption. On exit *OPTIONP is set to the beginning of the next | |
583 | otken or at the terminating NUL character. */ | |
584 | extern int getsubopt __P ((char **__optionp, __const char *__const *__tokens, | |
585 | char **__valuep)); | |
586 | #endif | |
587 | ||
588 | ||
2c6fe0bd UD |
589 | #ifdef __USE_XOPEN |
590 | ||
591 | /* Setup DES tables according KEY. */ | |
592 | extern void setkey __P ((__const char *__key)); | |
593 | #endif | |
594 | ||
595 | ||
28f540f4 RM |
596 | __END_DECLS |
597 | ||
598 | #endif /* stdlib.h */ |