home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / armlinux / alpha / PARTITIONS / USR_GZ / usr / include / stdlib.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-14  |  12.4 KB  |  388 lines

  1. /* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  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.
  8.  
  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.
  13.  
  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 Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. /*
  20.  *    ANSI Standard: 4.10 GENERAL UTILITIES    <stdlib.h>
  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.  
  34. #define    __need_Emath
  35. #include <errno.h>
  36.  
  37. /* Get HUGE_VAL (returned by strtod on overflow) from <float.h>.  */
  38. #define    __need_HUGE_VAL
  39. #include <float.h>
  40.  
  41. #if 0
  42. /* C++ would like it here. */
  43. /* I was told that was a bad idea. It's gone. Fix your C++ code. */
  44. #ifdef __cplusplus
  45. #include <getopt.h>
  46. #endif
  47. #endif
  48.  
  49. __BEGIN_DECLS
  50.  
  51. /* Returned by `div'.  */
  52. typedef struct
  53.   {
  54.     int quot;    /* Quotient.  */
  55.     int rem;    /* Remainder.  */
  56.   } div_t;
  57.  
  58. /* Returned by `ldiv'.  */
  59. typedef struct
  60.   {
  61.     long quot;    /* Quotient.  */
  62.     long rem;    /* Remainder.  */
  63.   } ldiv_t;
  64.  
  65.  
  66. /* The largest number rand will return (same as INT_MAX).  */
  67. #ifndef RAND_MAX
  68. #define    RAND_MAX    2147483647
  69. #endif
  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.  
  78. /* Maximum length of a multibyte character in the current locale.
  79.    This is just one until the fancy locale support is finished.  */
  80. #define    MB_CUR_MAX    1
  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.  
  90. /* Convert a string to a floating-point number.  */
  91. extern double strtod __P((__const char *__nptr, char **__endptr));
  92. /* Convert a string to a long integer.  */
  93. extern long int strtol __P((__const char *__nptr, char **__endptr,
  94.                    int __base));
  95. /* Convert a string to an unsigned long integer.  */
  96. extern unsigned long int strtoul __P((__const char *__nptr,
  97.                      char **__endptr, int __base));
  98.  
  99. #ifdef    __OPTIMIZE__
  100. #if defined(__cplusplus) || __GNUC__ >= 2
  101. extern __inline double atof (__const char *__nptr)
  102.     { return strtod(__nptr, (char **) NULL); }
  103. extern __inline int atoi (__const char *__nptr)
  104.     { return (int) strtol(__nptr, (char **) NULL, 10); }
  105. extern __inline long int atol (__const char *__nptr)
  106.     { return strtol(__nptr, (char **) NULL, 10); }
  107. #else
  108. #define    atof(nptr)    strtod((nptr), (char **) NULL)
  109. #define    atoi(nptr)    ((int) atol(nptr))
  110. #define    atol(nptr)    strtol((nptr), (char **) NULL, 10)
  111. #endif
  112. #endif    /* Optimizing.  */
  113.  
  114.  
  115. /* Return a random integer between 0 and RAND_MAX inclusive.  */
  116. extern int rand __P((void));
  117. /* Seed the random number generator with the given number.  */
  118. extern void srand __P((unsigned int __seed));
  119.  
  120. /* These are the functions that actually do things.  The `random', `srandom',
  121.    `initstate' and `setstate' functions are those from BSD Unices.
  122.    The `rand' and `srand' functions are required by the ANSI standard.
  123.    We provide both interfaces to the same random number generator.  */
  124. /* Return a random long integer between 0 and RAND_MAX inclusive.  */
  125. extern long int __random __P((void));
  126. /* Seed the random number generator with the given number.  */
  127. extern void __srandom __P((unsigned int __seed));
  128.  
  129. /* Initialize the random number generator to use state buffer STATEBUF,
  130.    of length STATELEN, and seed it with SEED.  Optimal lengths are 8, 16,
  131.    32, 64, 128 and 256, the bigger the better; values less than 8 will
  132.    cause an error and values greater than 256 will be rounded down.  */
  133. extern void * __initstate __P((unsigned int __seed, void * __statebuf,
  134.                    size_t __statelen));
  135. /* Switch the random number generator to state buffer STATEBUF,
  136.    which should have been previously initialized by `initstate'.  */
  137. extern void * __setstate __P((void * __statebuf));
  138.  
  139. #ifdef    __USE_BSD
  140. extern long int random __P((void));
  141. extern void srandom __P((unsigned int __seed));
  142. extern void * initstate __P((unsigned int __seed, void * __statebuf,
  143.                  size_t __statelen));
  144. extern void * setstate __P((void * __statebuf));
  145.  
  146. #ifdef    __OPTIMIZE__
  147. #if defined(__cplusplus) || __GNUC__ >= 2
  148. extern __inline long int random()
  149.     { return __random(); }
  150. extern __inline void srandom(unsigned int __seed)
  151.     { __srandom(__seed); }
  152. extern __inline __ptr_t initstate (unsigned int __seed,
  153.                 __ptr_t __statebuf, size_t __statelen)
  154.     { return __initstate (__seed, __statebuf, __statelen); }
  155. extern __inline __ptr_t setstate (__ptr_t __statebuf)
  156.     { return __setstate (__statebuf); }
  157. #else
  158. #define    random()        __random()
  159. #define    srandom(seed)        __srandom(seed)
  160. #define    initstate(s, b, n)    __initstate((s), (b), (n))
  161. #define    setstate(state)        __setstate(state)
  162. #endif
  163. #endif    /* Optimizing.  */
  164. #endif    /* Use BSD.  */
  165.  
  166. #ifdef    __OPTIMIZE__
  167. #if defined(__cplusplus) || __GNUC__ >= 2
  168. extern __inline int rand ()
  169.     { return (int) __random(); }
  170. extern __inline void srand(unsigned int __seed)
  171.     { __srandom(__seed); }
  172. #else
  173. #define    rand()        ((int) __random())
  174. #define    srand(seed)    __srandom(seed)
  175. #endif
  176. #endif    /* Optimizing.  */
  177.  
  178.  
  179. /* Allocate SIZE bytes of memory.  */
  180. extern void * malloc __P((size_t __size));
  181. /* Re-allocate the previously allocated block
  182.    in void *, making the new block SIZE bytes long.  */
  183. extern void * realloc __P((void * __ptr, size_t __size));
  184. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0.  */
  185. extern void * calloc __P((size_t __nmemb, size_t __size));
  186. /* Free a block allocated by `malloc', `realloc' or `calloc'.  */
  187. extern void free __P((void * __ptr));    
  188.  
  189. #ifdef    __USE_MISC
  190. /* Free a block.  An alias for `free'.    (Sun Unices).  */
  191. extern void cfree __P((void * __ptr));
  192.  
  193. #ifdef    __OPTIMIZE__
  194. #if defined(__cplusplus) || __GNUC__ >= 2
  195. extern __inline void cfree (__ptr_t __ptr)
  196.     { free (__ptr); }
  197. #else
  198. #define    cfree(ptr)    free(ptr)
  199. #endif
  200. #endif    /* Optimizing.  */
  201. #endif    /* Use misc.  */
  202.  
  203. /* Some ill behaved applications don't expect malloc (0) returns
  204.  * NULL. We put this hack here for them. For good behaved
  205.  * applications, we should define __MALLOC_0_RETURNS_NULL.
  206.  */
  207.  
  208. /* For backward compatibilities and X11R5 */
  209. #if (defined(MALLOC_0_RETURNS_NULL) || defined(NO_FIX_MALLOC)) \
  210.     && !defined(__MALLOC_0_RETURNS_NULL)
  211. #define __MALLOC_0_RETURNS_NULL
  212. #endif
  213.  
  214. #ifndef __MALLOC_0_RETURNS_NULL
  215. static __inline void* __gnu_calloc (size_t __nmemb, size_t __n)
  216. {
  217.   return calloc (__nmemb ? __nmemb : 1, __n ? __n : 1);
  218. }
  219.  
  220. static __inline void* __gnu_malloc (size_t __n)
  221. {
  222.   return malloc (__n ? __n : 1);
  223. }
  224.  
  225. #if 0
  226. #define calloc(nmemb,n)    __gnu_calloc((nmemb),(n))
  227. #define malloc(n)    __gnu_malloc((n))
  228. #else
  229. #define calloc        __gnu_calloc
  230. #define malloc        __gnu_malloc
  231. #endif
  232.  
  233. #endif
  234.  
  235. #if defined(__USE_GNU) || defined(__USE_BSD) || defined(__USE_MISC)
  236. #include <alloca.h>
  237. #endif    /* Use GNU, BSD, or misc.  */
  238.  
  239. #ifdef    __USE_BSD
  240. /* Allocate SIZE bytes on a page boundary.  The storage cannot be freed.  */
  241. extern void * valloc(size_t __size);
  242. #endif
  243.  
  244.  
  245. /* Abort execution and generate a core-dump.  */
  246. extern __NORETURN void abort __P((void)) __NORETURN2;
  247.  
  248.  
  249. /* Register a function to be called when `exit' is called.  */
  250. extern int atexit __P((void (*__func)(void)));
  251.  
  252. #ifdef    __USE_MISC
  253. /* Register a function to be called with the status
  254.    given to `exit' and the given argument.  */
  255. extern int on_exit __P((void (*__func)(int __status, void * __arg),
  256.                void * __arg));
  257. #endif
  258.  
  259. /* Call all functions registered with `atexit' and `on_exit',
  260.    in the reverse of the order in which they were registered
  261.    perform stdio cleanup, and terminate program execution with STATUS.  */
  262. extern __NORETURN void exit __P((int __status)) __NORETURN2;
  263.  
  264.  
  265. /* Return the value of envariable NAME, or NULL if it doesn't exist.  */
  266. extern char *getenv __P((__const char *__name));
  267.  
  268. #ifdef    __USE_SVID
  269. /* The SVID says this is in <stdio.h>, but this seems a better place.    */
  270. /* Put STRING, which is of the form "NAME=VALUE", in the environment.
  271.    If there is no `=', remove NAME from the environment.  */
  272. extern int putenv __P((__const char *__string));
  273. #endif
  274.  
  275. /* Execute the given line as a shell command.  */
  276. extern int system __P((__const char *__command));
  277.  
  278.  
  279. /* Shorthand for type of comparison functions.  */
  280. #ifndef __COMPAR_FN_T
  281. #define __COMPAR_FN_T
  282. typedef int (*__compar_fn_t) __P((__const void *, __const void *));
  283. #endif
  284.  
  285. #ifdef    __USE_GNU
  286. #define    comparison_fn_t    __compar_fn_t
  287. #endif
  288.  
  289. /* Do a binary search for KEY in BASE, which consists of NMEMB elements
  290.    of SIZE bytes each, using COMPAR to perform the comparisons.  */
  291. extern void * bsearch __P((__const void * __key, __const void * __base,
  292.                size_t __nmemb, size_t __size,
  293.                __compar_fn_t __compar));
  294.  
  295. /* Sort NMEMB elements of BASE, of SIZE bytes each,
  296.    using COMPAR to perform the comparisons.  */
  297. extern void qsort __P((void * __base, size_t __nmemb, size_t __size,
  298.               __compar_fn_t __compar));
  299.  
  300. /* Return the absolute value of X.  */
  301. extern __CONSTVALUE int abs __P((int __x)) __CONSTVALUE2;
  302. extern __CONSTVALUE long int labs __P((long int __x)) __CONSTVALUE2;
  303.  
  304. /* Return the `div_t' or `ldiv_t' representation
  305.    of the value of NUMER over DENOM. */
  306. /* GCC may have built-ins for these someday.  */
  307. extern __CONSTVALUE div_t div(int __numer, int __denom) __CONSTVALUE2;
  308. extern __CONSTVALUE ldiv_t ldiv(long int __numer,
  309.                 long int __denom) __CONSTVALUE2;
  310.  
  311.  
  312. /* Return the length of the multibyte character
  313.    in S, which is no longer than N.  */
  314. extern int mblen __P((__const char *__s, size_t __n));
  315. /* Return the length of the given multibyte character,
  316.    putting its `wchar_t' representation in *PWC.  */
  317. extern int mbtowc __P((wchar_t *__pwc, __const char *__s, size_t __n));
  318. /* Put the multibyte character represented
  319.    by WCHAR in S, returning its length.  */
  320. extern int wctomb __P((char *__s, wchar_t __wchar));
  321.  
  322. #ifdef    __OPTIMIZE__
  323. #if defined(__cplusplus) || __GNUC__ >= 2
  324. extern __inline int mblen (__const char *__s, size_t __n)
  325.     { return mbtowc((wchar_t *) NULL, __s, __n); }
  326. #else
  327. #define    mblen(s, n)    mbtowc((wchar_t *) 0, (s), (n))
  328. #endif
  329. #endif    /* Optimizing.  */
  330.  
  331.  
  332. /* Convert a multibyte string to a wide char string.  */
  333. extern size_t mbstowcs __P((wchar_t *__pwcs, __const char *__s, size_t __n));
  334. /* Convert a wide char string to multibyte string.  */
  335. extern size_t wcstombs __P((char *__s, __const wchar_t *__pwcs, size_t __n));
  336.  
  337.  
  338. /* I added the followings to Linux. H.J. */
  339. #if defined(__USE_MISC)
  340.  
  341. extern char **environ;
  342. extern char **__environ;
  343.  
  344. extern void*    memalign __P((size_t __alignment, size_t __size));
  345. extern void*    valloc __P((size_t __size));
  346.  
  347. extern char*    ecvt __P((double __value, size_t __ndigit, int *__decpt,
  348.             int *__sign));
  349. extern char*    fcvt __P((double __value, size_t __ndigit, int *__decpt,
  350.             int *__sign));
  351. extern char*    gcvt __P((double __value, size_t __ndigit, char *__buf));
  352.  
  353. #ifndef __cplusplus
  354. /* It is defined in libg++.a as builtin. */
  355. extern char*    dtoa __P((double __d, int __mode, int __ndigits,
  356.             int *__decpt, int *__sign, char **__rve));
  357. #endif
  358.  
  359. extern double    drand48 __P((void));
  360. extern double    erand48 __P((unsigned short int __xsubi[3]));
  361. extern long int    lrand48 __P((void));
  362. extern long int    nrand48 __P((unsigned short int __xsubi[3]));
  363. extern long int    mrand48 __P((void));
  364. extern long int    jrand48 __P((unsigned short int __xsubi[3]));
  365. extern void    srand48 __P((long int __seedval));
  366. extern unsigned short int
  367.             *seed48 __P((unsigned short int __seed16v[3]));
  368. extern void    lcong48 __P((unsigned short int __param[7]));
  369.  
  370. extern int    setenv __P((__const char *__name, __const char *__value,
  371.             int __overwrite));
  372. extern void    unsetenv __P((__const char *__name));
  373.  
  374. struct qelem {
  375.   struct qelem *q_forw;
  376.   struct qelem *q_back;
  377.   char q_data[1];
  378. };
  379.  
  380. extern void insque __P((struct qelem *__elem, struct qelem *__prev));
  381. extern void remque __P((struct qelem *__elem));
  382.  
  383. #endif
  384.  
  385. __END_DECLS
  386.  
  387. #endif    /* stdlib.h  */
  388.