home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !gcc / include / libscl / h / stdlib < prev    next >
Encoding:
Text File  |  2004-09-05  |  8.2 KB  |  247 lines

  1. /* stdlib.h
  2.  
  3.    For use with the GNU compilers and the SharedCLibrary.
  4.    (c) Copyright 1997, Nick Burrett.  */
  5.  
  6.  
  7. #ifndef __STDLIB_H
  8. #define __STDLIB_H
  9.  
  10. #ifndef __STDDEF_H
  11. #include <stddef.h>
  12. #endif
  13.  
  14. #ifndef __ERRNO_H
  15. #include <errno.h>
  16. #endif
  17.  
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21.  
  22. /* GCC has various useful declarations that can be made with the
  23.    __attribute__ syntax.  Disable its use for other compilers.  */
  24. #ifndef __GNUC__
  25. #ifndef __attribute__
  26. #define __attribute__(x) /* Ignore.  */
  27. #endif
  28. #endif
  29.  
  30. /* Returned by `div'.  */
  31. typedef struct div_t
  32. {
  33.   int quot, rem;
  34. } div_t;
  35.  
  36. /* Returned by `ldiv'.  */
  37. typedef struct ldiv_t
  38. {
  39.   long int quot, rem;
  40. } ldiv_t;
  41.  
  42. #ifdef __GNUC__
  43. /* Returned by `lldiv'.  */
  44. __extension__
  45. typedef struct
  46.   {
  47.     long long int quot; /* Quotient.  */
  48.     long long int rem;  /* Remainder.  */
  49.   } lldiv_t;
  50. #endif
  51.  
  52. #ifdef __EXIT_FAILURE
  53. #define EXIT_FAILURE __EXIT_FAILURE
  54.  
  55. #else
  56. /* Failing exit status.  */
  57. #define EXIT_FAILURE 1
  58. #endif
  59. /* Successful exit status.  */
  60. #define EXIT_SUCCESS 0
  61.  
  62. /* The largest number rand will return (same as INT_MAX).  */
  63. #define RAND_MAX 0x7fffffff
  64.  
  65. #define _ANSI_RAND_MAX 0x7fff
  66.  
  67. /* Maximum length of a multibyte character in the current locale.  */
  68. #define MB_CUR_MAX 1
  69.  
  70. /* Similar to the strtod function, except that it need not detect
  71.    overflow and underflow errors.  */
  72. extern double atof (const char *__string);
  73.  
  74. /* Similar to the strtol function with a base argument of 10,
  75.    except that it need not detect overflow errors.  */
  76. extern long int atol (const char *__string);
  77.  
  78. /* Similar to atol() but it returns an 'int' instead of a 'long int'.  */
  79. extern int atoi (const char *__string);
  80.  
  81. /* The strtod (string-to-double) function converts the initial part
  82.    of 'string' to a floating-point number.
  83.  
  84.    If 'tailptr' is not NULL, strtol will store a pointer to the remaining
  85.    characters in the string in '*tailptr'.  */
  86. extern double strtod (const char *__string, char **__tailptr);
  87.  
  88. /* The strtol (string-to-long) function converts the initial part
  89.    of 'string' to a signed integer, which is returned as a value
  90.    of 'long int'.  If 'base' is zero, decimal is assumed, unless
  91.    the digits being with '0' (specifying octal) or '0x'/'0X' (specifying
  92.    hexadecimal).  Otherwise 'base' must have a value between 2 and 35.
  93.  
  94.    If 'tailptr' is not NULL, strtol will store a pointer to the remaining
  95.    characters in the string in '*tailptr'.  */
  96. extern long int strtol (const char *__string, char **__tailptr, int __base);
  97.  
  98. /* The strtoul (string-to-unsigned-long) function is like strtol
  99.    except it deals with usigned numbers.  No + or - sign may
  100.    appear before the number.  */
  101. extern unsigned long int strtoul (const char *__string, char **__tailptr,
  102.                   int __base);
  103.  
  104. /* Returns the next pseudo-random number in the series. The value is
  105.    in the range from 0 to RAND_MAX.  */
  106. extern int rand (void);
  107.  
  108. /* Establish 'seed' as the seed for a new series of pseudo-random
  109.    numbers.  The default seed is 1.  Truly random numbers can
  110.    be achieved by srand (time (0)).  */
  111. extern void srand (unsigned int __seed);
  112.  
  113. extern int _ANSI_rand (void);
  114. extern void _ANSI_srand (unsigned int __seed);
  115.  
  116. /* Allocate a block long enough to contain a vector of 'count'
  117.    elements, each of size 'eltsize'. Its contents are cleared
  118.    to zero before 'calloc' returns.  */
  119. extern void *calloc (size_t __count, size_t __eltsize);
  120.  
  121. /* Deallocates the block of storage pointed at by 'ptr'.  */
  122. extern void free (void *__ptr);
  123.  
  124. /* Return a pointer to a newly allocated block 'size' bytes
  125.    long, or a null pointer if the block could not be allcated.  */
  126. extern void *malloc (size_t __size);
  127.  
  128. /* Change the size of the block whose address is 'ptr' to be 'newsize'.  */
  129. extern void *realloc (void *__ptr, size_t __newsize);
  130.  
  131. /* Cause abnormal program termination.  This function raises the
  132.    signal SIGABRT.  */
  133. extern void abort (void) __attribute__ ((__volatile__));
  134.  
  135. /* Register the function 'function' to be called at normal program
  136.    termination.  The function is called with no arguments.  */
  137. extern int atexit (void (*__function) (void));
  138.  
  139. /* Terminate a process with status 'status'. This function does
  140.    not return.  This function executes all functions registered
  141.    with atexit().  */
  142. extern void exit (int __status) __attribute__ ((__volatile__));
  143.  
  144. /* Return a string that is the value of the environment variable
  145.    'name'.  */
  146. extern char *getenv (const char *__name);
  147.  
  148. /* Execute 'command'. See _kernel_system () in kernel.h.  */
  149. extern int system (const char *__command);
  150.  
  151. /* Search the sorted array 'array' for an object that is equivalent
  152.    to 'key'. The array contains 'count' elements, each of which is
  153.    size 'size' bytes.
  154.  
  155.    The 'compare' function is used to perform the comparison.  This
  156.    function is called with two pointer arguments and should return
  157.    an integer less than, equal to, or greater than zero corresponding
  158.    to whether its first argument is considered less than, equal to,
  159.    or greater than its second argument.  */
  160. extern void *bsearch (const void *__key, const void *__array,
  161.               size_t __count, size_t __size,
  162.               int (*__compare) (const void *, const void *));
  163.  
  164. /* Sort the array 'array'. The array contains 'count' elements,
  165.    each of which is of size 'size'.
  166.  
  167.    The 'compare' function is similar in functionality to the bsearch
  168.    compare function.  */
  169. extern void qsort (void *__array, size_t __count, size_t __size,
  170.            int (*__compare) (const void *, const void *));
  171.  
  172. /* Return the non-negative version of x.  */
  173. extern int abs (int __x) __attribute__ ((__const__));
  174.  
  175. /* Integer divide x by y returning the quotient and remainder in
  176.    a div_t structure.  */
  177. extern div_t div (int __x, int __y) __attribute__ ((__const__));
  178.  
  179. /* Return the non-negative version of x. This is the long int equivalent
  180.    of abs().  */
  181. extern long int labs (long int __x) __attribute__ ((__const__));
  182.  
  183. /* Integer divide x by y returning the quotient and remainder in
  184.    a ldiv_t structure.  This is the long int version of div().  */
  185. extern ldiv_t ldiv (long int __x, long int __y) __attribute__ ((__const__));
  186.  
  187. /* Return the number of bytes that make up the multibyte character
  188.    beginning at 'string', never examining more than 'size' bytes.  */
  189. extern int mblen (const char *__string, size_t __size);
  190.  
  191. /* Convert the first multibyte character beginning at 'string' to
  192.    its corresponding wide character code.  The result is stored
  193.    in '*result'.  mbtowc never examines more than 'size' bytes.  */
  194. extern int mbtowc (wchar_t *__result, const char *__string, size_t __size);
  195.  
  196. /* Convert the wide character code 'wchar' to its corresponding
  197.    multibyte character sequence and store the result in 'string'.  */
  198. extern int wctomb (char *__string, wchar_t __wchar);
  199.  
  200. /* Convert a string of multibyte characters (string) to a
  201.    wide character array (string), storing not more than 'size'
  202.    wide characters.  */
  203. extern size_t mbstowcs (wchar_t *__wstring, const char *__string,
  204.             size_t __size);
  205.  
  206. /* Convert the null-terminated wide character array 'wstring'
  207.    into a string containing multibyte characters, storing not
  208.    more than 'size' bytes.  */
  209. extern size_t wcstombs (char *__string, const wchar_t *__wstring,
  210.             size_t __size);
  211.  
  212.  
  213. /* The following functions are libscl extensions.  */
  214.  
  215. __extension__
  216. extern lldiv_t lldiv (long long __numer, long long __denom) __attribute__ ((__const__));
  217.  
  218. /* Convert a string to a 64-bit long integer.  */
  219. extern long long atoll (const char *__string);
  220. #define atoll(s) strtoll(s, (char **) NULL, 10)
  221.  
  222. extern float strtof (const char *__restrict __string,
  223.                      char **__restrict __end);
  224. extern long double strtold (const char *__restrict __string,
  225.                             char **__restrict __end);
  226.  
  227. /* Convert a string to a 64-bit integer.  */
  228. __extension__
  229. extern long long strtoll (const char *__restrict __nptr,
  230.                           char **__restrict __endptr, int __base);
  231.  
  232. /* Convert a string to an unsigned 64-bit integer.  */
  233. __extension__
  234. extern unsigned long long strtoull (const char *__restrict __nptr,
  235.                                     char **__restrict __endptr, int __base);
  236.  
  237. /* Terminate the program with status.  Don't call any functions
  238.    registerd by atexit.  */
  239. extern void _Exit (int __status) __attribute__ ((__noreturn__));
  240.  
  241.  
  242. #ifdef __cplusplus
  243. }
  244. #endif
  245.  
  246. #endif
  247.