home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !unixlib / source / clib / h / stdlib < prev    next >
Encoding:
Text File  |  2004-09-07  |  10.7 KB  |  326 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/stdlib.h,v $
  4.  * $Date: 2004/09/07 14:05:10 $
  5.  * $Revision: 1.14 $
  6.  * $State: Exp $
  7.  * $Author: joty $
  8.  *
  9.  ***************************************************************************/
  10.  
  11. /* ANSI Standard 4.10: General Utilities <stdlib.h>.  */
  12.  
  13. #ifndef __STDLIB_H
  14. #define __STDLIB_H
  15.  
  16. #ifndef __UNIXLIB_FEATURES_H
  17. #include <unixlib/features.h>
  18. #endif
  19.  
  20. #define __need_size_t
  21. #define __need_wchar_t
  22. #define __need_NULL
  23. #include <stddef.h>
  24.  
  25. __BEGIN_DECLS
  26.  
  27. /* Returned by `div'.  */
  28. typedef struct
  29.   {
  30.     int quot;    /* Quotient.  */
  31.     int rem;    /* Remainder.  */
  32.   } div_t;
  33.  
  34. /* Returned by `ldiv'.  */
  35. typedef struct
  36.   {
  37.     long int quot;    /* Quotient.  */
  38.     long int rem;    /* Remainder.  */
  39.   } ldiv_t;
  40.  
  41. #ifdef __GNUC__
  42. /* Returned by `lldiv'.  */
  43. __extension__
  44. typedef struct
  45.   {
  46.     long long int quot;    /* Quotient.  */
  47.     long long int rem;    /* Remainder.  */
  48.   } lldiv_t;
  49. #endif
  50.  
  51. /* The largest number rand will return (same as INT_MAX).  */
  52. #define    RAND_MAX    2147483647
  53.  
  54.  
  55. /* Successful exit status.  */
  56. #define EXIT_SUCCESS 0
  57. /* Failing exit status.  */
  58. #define EXIT_FAILURE 1
  59.  
  60. /* Maximum length of a multibyte character in the current locale.  */
  61. #define    MB_CUR_MAX    1
  62.  
  63. /* Abort execution and generate a core-dump.  */
  64. extern void abort (void) __attribute__ ((__noreturn__));
  65.  
  66. /* Register a function to be called when exit is called.  */
  67. extern int atexit (void (*__atexit_function) (void));
  68.  
  69. /* Terminate the program with status. Call all functions registerd
  70.    by atexit.  */
  71. extern void exit (int __status) __attribute__ ((__noreturn__));
  72.  
  73. /* Terminate the program with status.  Don't call any functions
  74.    registerd by atexit.  */
  75. extern void _Exit (int __status) __attribute__ ((__noreturn__));
  76.  
  77. /* Return the value of environment variable 'name'.  */
  78. extern char *getenv (const char *__name) __THROW;
  79.  
  80. /* Set NAME to VALUE in the environment.
  81.    If REPLACE is nonzero, overwrite an existing value.  */
  82. extern int setenv (const char *__name, const char *__value, int __replace)
  83.      __THROW;
  84.  
  85. /* Remove NAME from the environment.  */
  86. extern void unsetenv (const char *__name) __THROW;
  87.  
  88. /* The `clearenv' was planned to be added to POSIX.1 but probably
  89.    never made it.  Nevertheless the POSIX.9 standard (POSIX bindings
  90.    for Fortran 77) requires this function.  */
  91. extern int clearenv (void) __THROW;
  92.  
  93. /* Put string, which is of the form "NAME=VALUE" in the environment.  */
  94. extern int putenv (const char *__string) __THROW;
  95.  
  96. /* Execute the given line via the CLI.  */
  97. extern int system (const char *__command) __THROW;
  98.  
  99. /* Canonicalise a filename */
  100. extern char *realpath (const char *__file_name, char *__resolved_name)
  101.      __THROW;
  102.  
  103. #ifdef __UNIXLIB_INTERNALS
  104.  
  105. /* Definitions for the atexit array of functions that are to be
  106.    called when the process calls exit.  ANSI requires a minimum
  107.    of 32, however C++ requires 33.  */
  108. #define __MAX_ATEXIT_FUNCTION_COUNT 33
  109.  
  110. extern void (*__atexit_function_array[__MAX_ATEXIT_FUNCTION_COUNT]) (void);
  111. extern int __atexit_function_count;
  112.  
  113. #endif  /* __UNIXLIB_INTERNALS */
  114.  
  115. /* Allocate nmemb elements of size bytes each. Initialise
  116.    all members to zero.  */
  117. extern void *calloc (size_t __nmemb, size_t __size)
  118.      __THROW  __attribute_malloc__;
  119.  
  120. /* Free a block allocated by malloc, calloc or realloc.  */
  121. extern void free (void *__ptr) __THROW;
  122.  
  123. /* Allocate __size bytes of memory.  */
  124. extern void *malloc (size_t __size) __THROW __attribute_malloc__;
  125.  
  126. /* Re-allocate the previously malloc'd block, ptr, making the
  127.    new block size bytes.  */
  128. extern void *realloc (void *__ptr, size_t __size) __THROW __attribute_malloc__;
  129.  
  130. /* Allocate size bytes on a page boundary. The storage cannot be freed.  */
  131. extern void *valloc (size_t __bytes) __THROW __attribute_malloc__;
  132.  
  133. /* src.c.alloc thinks these are in stdio.h, but that feels wrong ... */
  134. extern void *memalign (size_t __alignment,
  135.                size_t __bytes) __THROW __attribute_malloc__;
  136. extern void cfree (void *__mem) __THROW;
  137. extern int malloc_trim (size_t) __THROW;
  138.  
  139. /* Return a random integer between 0 and 2^31 (System V interface).  */
  140. extern int rand (void) __THROW;
  141.  
  142. /* Seed the random number generator with the given number.  */
  143. extern void srand (long __seed) __THROW;
  144.  
  145. # include <sys/types.h> /* we need int32_t... */
  146. /* Return a random integer between 0 and RAND_MAX (BSD interface).  */
  147. extern long int random (void) __THROW;
  148.  
  149. /* Seed the random number generator (BSD interface).  */
  150. extern void srandom (unsigned int __seed) __THROW;
  151.  
  152. /* Initialize the random number generator to use state buffer STATEBUF,
  153.    of length STATELEN, and seed it with SEED.  Optimal lengths are 8, 16,
  154.    32, 64, 128 and 256, the bigger the better; values less than 8 will
  155.    cause an error and values greater than 256 will be rounded down.  */
  156. extern char *initstate (unsigned int __seed, char *__statebuf,
  157.                         size_t __statelen) __THROW;
  158.  
  159. /* Switch the random number generator to state buffer STATEBUF,
  160.    which should have been previously initialized by `initstate'.  */
  161. extern char *setstate (char *__statebuf) __THROW;
  162.  
  163. /* Return the absolute value of x.  */
  164. extern int abs (int __x) __THROW __attribute__ ((__const__));
  165. extern long int    labs (long int __x) __THROW __attribute__ ((__const__));
  166.  
  167. /* Return numerator divided by denominator.  */
  168. extern div_t div (int __numer, int __denom)
  169.      __THROW __attribute__ ((__const__));
  170. extern ldiv_t ldiv (long __numer, long __denom)
  171.      __THROW __attribute__ ((__const__));
  172. #ifdef __GNUC__
  173. __extension__
  174. extern lldiv_t lldiv (long long __numer, long long __denom)
  175.      __THROW __attribute__ ((__const__));
  176. #endif
  177.  
  178. __BEGIN_NAMESPACE_STD
  179. /* Convert a string to a floating-point number.  */
  180. extern double atof (__const char *__nptr) __THROW __attribute_pure__;
  181. /* Convert a string to an integer.  */
  182. extern int atoi (__const char *__nptr) __THROW __attribute_pure__;
  183. /* Convert a string to a long integer.  */
  184. extern long int atol (__const char *__nptr) __THROW __attribute_pure__;
  185. __END_NAMESPACE_STD
  186.  
  187. #if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC)
  188. __BEGIN_NAMESPACE_C99
  189. /* Convert a string to a long long integer.  */
  190. __extension__ extern long long int atoll (__const char *__nptr)
  191.      __THROW __attribute_pure__;
  192. __END_NAMESPACE_C99
  193. #endif
  194.  
  195. __BEGIN_NAMESPACE_STD
  196. /* Convert a string to a floating-point number.  */
  197. extern double strtod (__const char *__restrict __nptr,
  198.               char **__restrict __endptr) __THROW;
  199. __END_NAMESPACE_STD
  200.  
  201. #ifdef    __USE_ISOC99
  202. __BEGIN_NAMESPACE_C99
  203. /* Likewise for `float' and `long double' sizes of floating-point numbers.  */
  204. extern float strtof (__const char *__restrict __nptr,
  205.              char **__restrict __endptr) __THROW;
  206.  
  207. extern long double strtold (__const char *__restrict __nptr,
  208.                 char **__restrict __endptr) __THROW;
  209. __END_NAMESPACE_C99
  210. #endif
  211.  
  212. __BEGIN_NAMESPACE_STD
  213. /* Convert a string to a long integer.  */
  214. extern long int strtol (__const char *__restrict __nptr,
  215.             char **__restrict __endptr, int __base) __THROW;
  216. /* Convert a string to an unsigned long integer.  */
  217. extern unsigned long int strtoul (__const char *__restrict __nptr,
  218.                   char **__restrict __endptr, int __base)
  219.      __THROW;
  220. __END_NAMESPACE_C99
  221.  
  222. /*#if defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC)*/
  223. __BEGIN_NAMESPACE_C99
  224. /* Convert a string to a quadword integer.  */
  225. __extension__
  226. extern long long int strtoll (__const char *__restrict __nptr,
  227.                   char **__restrict __endptr, int __base) __THROW;
  228. /* Convert a string to an unsigned quadword integer.  */
  229. __extension__
  230. extern unsigned long long int strtoull (__const char *__restrict __nptr,
  231.                     char **__restrict __endptr, int __base)
  232.      __THROW;
  233. __END_NAMESPACE_C99
  234. /*#endif*/ /* ISO C99 or GCC and use MISC.  */
  235.  
  236. #ifdef __USE_EXTERN_INLINES
  237. /* Define inline functions which call the internal entry points.  */
  238.  
  239. __BEGIN_NAMESPACE_STD
  240. extern __inline double
  241. atof (__const char *__nptr) __THROW
  242. {
  243.   return strtod (__nptr, (char **) NULL);
  244. }
  245. extern __inline int
  246. atoi (__const char *__nptr) __THROW
  247. {
  248.   return (int) strtol (__nptr, (char **) NULL, 10);
  249. }
  250. extern __inline long int
  251. atol (__const char *__nptr) __THROW
  252. {
  253.   return strtol (__nptr, (char **) NULL, 10);
  254. }
  255. __END_NAMESPACE_STD
  256.  
  257. # if defined __USE_MISC || defined __USE_ISOC99
  258. __BEGIN_NAMESPACE_C99
  259. __extension__ extern __inline long long int
  260. atoll (__const char *__nptr) __THROW
  261. {
  262.   return strtoll (__nptr, (char **) NULL, 10);
  263. }
  264. __END_NAMESPACE_C99
  265. # endif
  266. #endif /* Optimizing and Inlining.  */
  267.  
  268.  
  269. /* Do a binary search for 'key' in 'base', which consists of
  270.    'nmemb' elements of 'size' bytes each, using 'compare' to
  271.    perform the comparisons.  */
  272. extern void *bsearch (const void *__key, const void *__base,
  273.               size_t __nmemb, size_t __size,
  274.               int (*__compare)(const void *, const void *)) __THROW;
  275.  
  276. /* Sort 'nmemb' elements of 'base', or 'size' bytes each.
  277.    Use 'compare' to perform the comparisons.  */
  278. extern void qsort (void *__base, size_t __nmemb, size_t __size,
  279.            int (*__compare)(const void *,const void *)) __THROW;
  280.  
  281. /* Return the length of a multibyte character in 's' which is
  282.    no longer than n.  */
  283. extern int mblen (const char *__s, size_t __n) __THROW;
  284. extern size_t mbstowcs (wchar_t *__wchar, const char *__s, size_t __n) __THROW;
  285. extern int mbtowc (wchar_t *__wchar, const char *__s, size_t __n) __THROW;
  286. extern size_t wcstombs (char *__s, const wchar_t *__wchar, size_t __n) __THROW;
  287. extern int wctomb (char *__s, wchar_t __wchar) __THROW;
  288.  
  289. #ifndef __ALLOCA_H
  290. #include <alloca.h>
  291. #endif
  292.  
  293. /* Efficient (?) internal decimal to ascii function used by printf() et al */
  294. extern char *__dtoa(double __d, int __mode, int __ndigits,
  295.             int *__decpt, int *__sign, char **__rve) __THROW;
  296.  
  297. /* Parse comma separated suboption from 'option' and match against
  298.    strings in 'tokens'. Return index with *value set to optional value.  */
  299. extern int getsubopt (char **__option, const char *const *__tokens,
  300.               char **__value) __THROW;
  301. extern char *suboptarg;
  302.  
  303. /* System V style 48-bit random number generator functions.  */
  304.  
  305. /* Return a non-negative, double-precision floating-point value in
  306.    the range 0.0 to 1.0.  */
  307. extern double drand48 (void) __THROW;
  308. extern double erand48 (unsigned short int __xsubi[3]) __THROW;
  309.  
  310. /* Return non-negative, long integer in the range 0 to 2^31.  */
  311. extern long int lrand48 (void) __THROW;
  312. extern long int nrand48 (unsigned short int __xsubi[3]) __THROW;
  313.  
  314. /* Return signed, long integers in the range -2^31 to 2^31.  */
  315. extern long int mrand48 (void) __THROW;
  316. extern long int jrand48 (unsigned short int __xsubi[3]) __THROW;
  317.  
  318. /* Seed random number generator.  */
  319. extern void srand48 (long int __seedval) __THROW;
  320. extern unsigned short int *seed48 (unsigned short int __seed16v[3]) __THROW;
  321. extern void lcong48 (unsigned short int __param[7]) __THROW;
  322.  
  323. __END_DECLS
  324.  
  325. #endif
  326.