cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

stdlib.h (4778B)


      1/** file stdlib.h
      2    'Standard library' functions, for whatever that means.
      3*/
      4#ifndef STDLIB_INCLUDE
      5#define STDLIB_INCLUDE
      6
      7#include <types.h>
      8
      9#if !defined(__SDCC_mcs51) && !defined(__SDCC_ds390) && !defined(__SDCC_ds400) && !defined(__SDCC_hc08) && !defined(__SDCC_s08) && !defined(__SDCC_pic14) && !defined(__SDCC_pic16) && !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15)
     10#define __reentrant
     11#endif
     12
     13/** Causes normal program termination and the value of status is
     14    returned to the parent.
     15    All open streams are flushed and closed.
     16*/
     17void exit(int status) OLDCALL;
     18
     19#if 0
     20/** Compatibility function.  Not implemented.
     21 */
     22int getkey(void) OLDCALL;
     23#endif
     24
     25/** Returns the absolute value of int __i__
     26    @param i   Int to obtain absolute value of
     27
     28    If i is negative, returns -i; else returns i.
     29*/
     30int abs(int i) OLDCALL;
     31
     32
     33/** Returns the absolute value of long int __num__
     34
     35    @param num   Long integer to obtain absolute value of
     36 */
     37long labs(long num) OLDCALL;
     38
     39
     40/** Converts an ASCII string to an int
     41
     42    @param s    String to convert to an int
     43
     44    The string may be of the format
     45    \code{.c}
     46     [\s]*[+-][\d]+[\D]*
     47     \endcode
     48    i.e. any number of spaces, an optional + or -, then an
     49    arbitrary number of digits.
     50
     51    The result is undefined if the number doesnt fit in an int.
     52
     53    Returns: Int value of string
     54 */
     55int atoi(const char *s);
     56
     57
     58/** Converts an ASCII string to a long.
     59    @param s    String to convert to an long int
     60    @see atoi()
     61
     62    Returns: Long int value of string
     63 */
     64long atol(const char *s);
     65
     66/** Converts an int into a base 10 ASCII string.
     67    @param n      Int to convert to a string
     68    @param s      String to store the converted number
     69    @param radix  Numerical base for converted number, ex: 10 is decimal base
     70                  (parameter is required but not utilized on Game Boy and Analogue Pocket)
     71
     72    Returns:    Pointer to converted string
     73 */
     74char *itoa(int n, char *s, unsigned char radix) OLDCALL;
     75
     76/** Converts an unsigned int into a base 10 ASCII string.
     77    @param n      Unsigned Int to convert to a string
     78    @param s      String to store the converted number
     79    @param radix  Numerical base for converted number, ex: 10 is decimal base
     80                  (parameter is required but not utilized on Game Boy and Analogue Pocket)
     81
     82    Returns:    Pointer to converted string
     83 */
     84char *uitoa(unsigned int n, char *s, unsigned char radix) OLDCALL;
     85
     86/** Converts a long into a base 10 ASCII string.
     87    @param n      Long int to convert to a string
     88    @param s      String to store the converted number
     89    @param radix  Numerical base for converted number, ex: 10 is decimal base
     90                  (parameter is required but not utilized on Game Boy and Analogue Pocket)
     91
     92    Returns:    Pointer to converted string
     93 */
     94char *ltoa(long n, char *s, unsigned char radix) OLDCALL;
     95
     96/** Converts an unsigned long into a base 10 ASCII string.
     97    @param n      Unsigned Long Int to convert to a string
     98    @param s      String to store the converted number
     99    @param radix  Numerical base for converted number, ex: 10 is decimal base
    100                  (parameter is required but not utilized on Game Boy and Analogue Pocket)
    101
    102    Returns:    Pointer to converted string
    103 */
    104char *ultoa(unsigned long n, char *s, unsigned char radix) OLDCALL;
    105
    106
    107/** Memory allocation functions
    108 */
    109void *calloc (size_t nmemb, size_t size);
    110void *malloc (size_t size);
    111void *realloc (void *ptr, size_t size);
    112#if __STDC_VERSION__ >= 201112L
    113inline void *aligned_alloc(size_t alignment, size_t size)
    114{
    115  (void)alignment;
    116  return malloc(size);
    117}
    118#endif
    119extern void free (void * ptr);
    120
    121/* Searching and sorting utilities (ISO C11 7.22.5) */
    122/** search a sorted array of __nmemb__ items
    123    @param key      Pointer to object that is the key for the search
    124    @param base     Pointer to first object in the array to search
    125    @param nmemb    Number of elements in the array
    126    @param size     Size in bytes of each element in the array
    127    @param compar   Function used to compare two elements of the array
    128
    129    Returns: Pointer to array entry that matches the search key.
    130             If key is not found, NULL is returned.
    131*/
    132extern void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *) __reentrant);
    133
    134
    135/** Sort an array of __nmemb__ items
    136    @param base     Pointer to first object in the array to sort
    137    @param nmemb    Number of elements in the array
    138    @param size     Size in bytes of each element in the array
    139    @param compar   Function used to compare and sort two elements of the array
    140*/
    141extern void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *) __reentrant);
    142
    143#endif