home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !gcc / include / libscl / h / stdlib < prev    next >
Encoding:
Text File  |  2006-09-17  |  9.6 KB  |  267 lines

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