1 /* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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
16 not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
20 * ANSI Standard: 4.10 GENERAL UTILITIES <stdlib.h>
28 /* Get size_t, wchar_t and NULL from <stddef.h>. */
30 #define __need_wchar_t
39 /* Returned by `div'. */
42 int quot; /* Quotient. */
43 int rem; /* Remainder. */
46 /* Returned by `ldiv'. */
49 long int quot; /* Quotient. */
50 long int rem; /* Remainder. */
54 /* The largest number rand will return (same as INT_MAX). */
55 #define RAND_MAX 2147483647
58 /* We define these the same for all machines.
59 Changes from this to the outside world should be done in `_exit'. */
60 #define EXIT_FAILURE 1 /* Failing exit status. */
61 #define EXIT_SUCCESS 0 /* Successful exit status. */
64 /* Maximum length of a multibyte character in the current locale.
65 This is just one until the fancy locale support is finished. */
69 /* Convert a string to a floating-point number. */
70 extern double atof __P ((__const char *__nptr));
71 /* Convert a string to an integer. */
72 extern int atoi __P ((__const char *__nptr));
73 /* Convert a string to a long integer. */
74 extern long int atol __P ((__const char *__nptr));
76 /* Convert a string to a floating-point number. */
77 extern double strtod __P ((__const char *__nptr, char **__endptr));
80 /* Likewise for `float' and `long double' sizes of floating-point numbers. */
81 extern float __strtof __P ((__const char *__nptr, char **__endptr));
82 extern float strtof __P ((__const char *__nptr, char **__endptr));
83 extern __long_double_t __strtold __P ((__const char *__nptr, char **__endptr));
84 extern __long_double_t strtold __P ((__const char *__nptr, char **__endptr));
87 /* Convert a string to a long integer. */
88 extern long int strtol __P ((__const char *__nptr, char **__endptr,
90 /* Convert a string to an unsigned long integer. */
91 extern unsigned long int strtoul __P ((__const char *__nptr,
92 char **__endptr, int __base));
94 #if defined (__GNUC__) && defined (__USE_BSD)
95 /* Convert a string to a quadword integer. */
96 extern long long int strtoq __P ((__const char *__nptr, char **__endptr,
98 /* Convert a string to an unsigned quadword integer. */
99 extern unsigned long long int strtouq __P ((__const char *__nptr,
100 char **__endptr, int __base));
101 #endif /* GCC and use BSD. */
103 #if defined (__OPTIMIZE__) && __GNUC__ >= 2
104 extern __inline double atof (__const char *__nptr)
105 { return strtod(__nptr, (char **) NULL); }
106 extern __inline int atoi (__const char *__nptr)
107 { return (int) strtol (__nptr, (char **) NULL, 10); }
108 extern __inline long int atol (__const char *__nptr)
109 { return strtol (__nptr, (char **) NULL, 10); }
110 #endif /* Optimizing GCC >=2. */
113 /* Return a random integer between 0 and RAND_MAX inclusive. */
114 extern int rand __P ((void));
115 /* Seed the random number generator with the given number. */
116 extern void srand __P ((unsigned int __seed));
118 /* These are the functions that actually do things. The `random', `srandom',
119 `initstate' and `setstate' functions are those from BSD Unices.
120 The `rand' and `srand' functions are required by the ANSI standard.
121 We provide both interfaces to the same random number generator. */
122 /* Return a random long integer between 0 and RAND_MAX inclusive. */
123 extern long int __random __P ((void));
124 /* Seed the random number generator with the given number. */
125 extern void __srandom __P ((unsigned int __seed));
127 /* Initialize the random number generator to use state buffer STATEBUF,
128 of length STATELEN, and seed it with SEED. Optimal lengths are 8, 16,
129 32, 64, 128 and 256, the bigger the better; values less than 8 will
130 cause an error and values greater than 256 will be rounded down. */
131 extern __ptr_t __initstate __P ((unsigned int __seed, __ptr_t __statebuf,
133 /* Switch the random number generator to state buffer STATEBUF,
134 which should have been previously initialized by `initstate'. */
135 extern __ptr_t __setstate __P ((__ptr_t __statebuf));
138 extern long int random __P ((void));
139 extern void srandom __P ((unsigned int __seed));
140 extern __ptr_t initstate __P ((unsigned int __seed, __ptr_t __statebuf,
142 extern __ptr_t setstate __P ((__ptr_t __statebuf));
144 #if defined (__OPTIMIZE__) && __GNUC__ >= 2
145 extern __inline long int random (void)
146 { return __random(); }
147 extern __inline void srandom (unsigned int __seed)
148 { __srandom(__seed); }
149 extern __inline __ptr_t initstate (unsigned int __seed,
150 __ptr_t __statebuf, size_t __statelen)
151 { return __initstate (__seed, __statebuf, __statelen); }
152 extern __inline __ptr_t setstate (__ptr_t __statebuf)
153 { return __setstate (__statebuf); }
154 #endif /* Optimizing GCC >=2. */
155 #endif /* Use BSD. */
158 /* Allocate SIZE bytes of memory. */
159 extern __ptr_t malloc __P ((size_t __size));
160 /* Re-allocate the previously allocated block
161 in __ptr_t, making the new block SIZE bytes long. */
162 extern __ptr_t realloc __P ((__ptr_t __ptr, size_t __size));
163 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
164 extern __ptr_t calloc __P ((size_t __nmemb, size_t __size));
165 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
166 extern void free __P ((__ptr_t __ptr));
169 /* Free a block. An alias for `free'. (Sun Unices). */
170 extern void cfree __P ((__ptr_t __ptr));
171 #endif /* Use misc. */
173 #if defined(__USE_GNU) || defined(__USE_BSD) || defined(__USE_MISC)
175 #endif /* Use GNU, BSD, or misc. */
178 /* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
179 extern __ptr_t valloc __P ((size_t __size));
183 /* Abort execution and generate a core-dump. */
184 extern void abort __P ((void)) __attribute__ ((__noreturn__));
187 /* Register a function to be called when `exit' is called. */
188 extern int atexit __P ((void (*__func) (void)));
191 /* Register a function to be called with the status
192 given to `exit' and the given argument. */
193 extern int on_exit __P ((void (*__func) (int __status, __ptr_t __arg),
197 /* Call all functions registered with `atexit' and `on_exit',
198 in the reverse of the order in which they were registered
199 perform stdio cleanup, and terminate program execution with STATUS. */
200 extern void exit __P ((int __status)) __attribute__ ((__noreturn__));
203 /* Return the value of envariable NAME, or NULL if it doesn't exist. */
204 extern char *getenv __P ((__const char *__name));
207 /* The SVID says this is in <stdio.h>, but this seems a better place. */
208 /* Put STRING, which is of the form "NAME=VALUE", in the environment.
209 If there is no `=', remove NAME from the environment. */
210 extern int putenv __P ((__const char *__string));
214 /* Set NAME to VALUE in the environment.
215 If REPLACE is nonzero, overwrite an existing value. */
216 extern int setenv __P ((__const char *__name, __const char *__value,
220 /* Execute the given line as a shell command. */
221 extern int system __P ((__const char *__command));
224 /* Shorthand for type of comparison functions. */
225 typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
228 typedef __compar_fn_t comparison_fn_t;
231 /* Do a binary search for KEY in BASE, which consists of NMEMB elements
232 of SIZE bytes each, using COMPAR to perform the comparisons. */
233 extern __ptr_t bsearch __P ((__const __ptr_t __key, __const __ptr_t __base,
234 size_t __nmemb, size_t __size,
235 __compar_fn_t __compar));
237 /* Sort NMEMB elements of BASE, of SIZE bytes each,
238 using COMPAR to perform the comparisons. */
239 extern void qsort __P ((__ptr_t __base, size_t __nmemb, size_t __size,
240 __compar_fn_t __compar));
245 /* The `const' keyword tells GCC that a function's return value is
246 based solely on its arguments, and there are no side-effects. */
247 #define __CONSTVALUE __const
251 #endif /* __CONSTVALUE not defined. */
253 /* Return the absolute value of X. */
254 extern __CONSTVALUE int abs __P ((int __x));
255 extern __CONSTVALUE long int labs __P ((long int __x));
258 /* Return the `div_t' or `ldiv_t' representation
259 of the value of NUMER over DENOM. */
260 /* GCC may have built-ins for these someday. */
261 extern __CONSTVALUE div_t div __P ((int __numer, int __denom));
262 extern __CONSTVALUE ldiv_t ldiv __P ((long int __numer, long int __denom));
265 /* Return the length of the multibyte character
266 in S, which is no longer than N. */
267 extern int mblen __P ((__const char *__s, size_t __n));
268 /* Return the length of the given multibyte character,
269 putting its `wchar_t' representation in *PWC. */
270 extern int mbtowc __P ((wchar_t * __pwc, __const char *__s, size_t __n));
271 /* Put the multibyte character represented
272 by WCHAR in S, returning its length. */
273 extern int wctomb __P ((char *__s, wchar_t __wchar));
275 #if defined (__OPTIMIZE__) && __GNUC__ >= 2
276 extern __inline int mblen (__const char *__s, size_t __n)
277 { return mbtowc ((wchar_t *) NULL, __s, __n); }
278 #endif /* Optimizing GCC >=2. */
281 /* Convert a multibyte string to a wide char string. */
282 extern size_t mbstowcs __P ((wchar_t * __pwcs, __const char *__s, size_t __n));
283 /* Convert a wide char string to multibyte string. */
284 extern size_t wcstombs __P ((char *__s, __const wchar_t * __pwcs, size_t __n));
289 #endif /* stdlib.h */