|
|
1.1 ! root 1: #ifndef STDLIB_H ! 2: #define STDLIB_H ! 3: ! 4: FILE_LICENCE ( GPL2_OR_LATER ); ! 5: ! 6: #include <stdint.h> ! 7: #include <assert.h> ! 8: #include <ctype.h> ! 9: ! 10: /***************************************************************************** ! 11: * ! 12: * Numeric parsing ! 13: * ! 14: **************************************************************************** ! 15: */ ! 16: ! 17: static inline int strtoul_base ( const char **pp, int base ) ! 18: { ! 19: const char *p = *pp; ! 20: ! 21: while ( isspace ( *p ) ) ! 22: p++; ! 23: ! 24: if ( base == 0 ) { ! 25: base = 10; ! 26: if ( *p == '0' ) { ! 27: p++; ! 28: base = 8; ! 29: if ( ( *p | 0x20 ) == 'x' ) { ! 30: p++; ! 31: base = 16; ! 32: } ! 33: } ! 34: } ! 35: ! 36: *pp = p; ! 37: ! 38: return base; ! 39: } ! 40: ! 41: static inline unsigned int strtoul_charval ( unsigned int charval ) ! 42: { ! 43: if ( charval >= 'a' ) { ! 44: charval = ( charval - 'a' + 10 ); ! 45: } else if ( charval >= 'A' ) { ! 46: charval = ( charval - 'A' + 10 ); ! 47: } else if ( charval <= '9' ) { ! 48: charval = ( charval - '0' ); ! 49: } ! 50: ! 51: return charval; ! 52: } ! 53: ! 54: extern unsigned long strtoul ( const char *p, char **endp, int base ); ! 55: extern unsigned long long strtoull ( const char *p, char **endp, int base ); ! 56: ! 57: ! 58: /***************************************************************************** ! 59: * ! 60: * Memory allocation ! 61: * ! 62: **************************************************************************** ! 63: */ ! 64: ! 65: extern void * __malloc malloc ( size_t size ); ! 66: extern void * realloc ( void *old_ptr, size_t new_size ); ! 67: extern void free ( void *ptr ); ! 68: extern void * __malloc zalloc ( size_t len ); ! 69: ! 70: /** ! 71: * Allocate cleared memory ! 72: * ! 73: * @v nmemb Number of members ! 74: * @v size Size of each member ! 75: * @ret ptr Allocated memory ! 76: * ! 77: * Allocate memory as per malloc(), and zero it. ! 78: * ! 79: * This is implemented as a static inline, with the body of the ! 80: * function in zalloc(), since in most cases @c nmemb will be 1 and ! 81: * doing the multiply is just wasteful. ! 82: */ ! 83: static inline void * __malloc calloc ( size_t nmemb, size_t size ) { ! 84: return zalloc ( nmemb * size ); ! 85: } ! 86: ! 87: /***************************************************************************** ! 88: * ! 89: * Random number generation ! 90: * ! 91: **************************************************************************** ! 92: */ ! 93: ! 94: extern long int random ( void ); ! 95: extern void srandom ( unsigned int seed ); ! 96: ! 97: static inline int rand ( void ) { ! 98: return random(); ! 99: } ! 100: ! 101: static inline void srand ( unsigned int seed ) { ! 102: srandom ( seed ); ! 103: } ! 104: ! 105: /***************************************************************************** ! 106: * ! 107: * Miscellaneous ! 108: * ! 109: **************************************************************************** ! 110: */ ! 111: ! 112: extern int system ( const char *command ); ! 113: extern __asmcall int main ( void ); ! 114: ! 115: #endif /* STDLIB_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.