[e16e8f2] | 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 | |
---|
| 9 | /***************************************************************************** |
---|
| 10 | * |
---|
| 11 | * Numeric parsing |
---|
| 12 | * |
---|
| 13 | **************************************************************************** |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | extern unsigned long strtoul ( const char *p, char **endp, int base ); |
---|
| 17 | |
---|
| 18 | /***************************************************************************** |
---|
| 19 | * |
---|
| 20 | * Memory allocation |
---|
| 21 | * |
---|
| 22 | **************************************************************************** |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | extern void * __malloc malloc ( size_t size ); |
---|
| 26 | extern void * realloc ( void *old_ptr, size_t new_size ); |
---|
| 27 | extern void free ( void *ptr ); |
---|
| 28 | extern void * __malloc zalloc ( size_t len ); |
---|
| 29 | |
---|
| 30 | /** |
---|
| 31 | * Allocate cleared memory |
---|
| 32 | * |
---|
| 33 | * @v nmemb Number of members |
---|
| 34 | * @v size Size of each member |
---|
| 35 | * @ret ptr Allocated memory |
---|
| 36 | * |
---|
| 37 | * Allocate memory as per malloc(), and zero it. |
---|
| 38 | * |
---|
| 39 | * This is implemented as a static inline, with the body of the |
---|
| 40 | * function in zalloc(), since in most cases @c nmemb will be 1 and |
---|
| 41 | * doing the multiply is just wasteful. |
---|
| 42 | */ |
---|
| 43 | static inline void * __malloc calloc ( size_t nmemb, size_t size ) { |
---|
| 44 | return zalloc ( nmemb * size ); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | /***************************************************************************** |
---|
| 48 | * |
---|
| 49 | * Random number generation |
---|
| 50 | * |
---|
| 51 | **************************************************************************** |
---|
| 52 | */ |
---|
| 53 | |
---|
| 54 | extern long int random ( void ); |
---|
| 55 | extern void srandom ( unsigned int seed ); |
---|
| 56 | |
---|
| 57 | static inline int rand ( void ) { |
---|
| 58 | return random(); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | static inline void srand ( unsigned int seed ) { |
---|
| 62 | srandom ( seed ); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /***************************************************************************** |
---|
| 66 | * |
---|
| 67 | * Miscellaneous |
---|
| 68 | * |
---|
| 69 | **************************************************************************** |
---|
| 70 | */ |
---|
| 71 | |
---|
| 72 | extern int system ( const char *command ); |
---|
| 73 | extern __asmcall int main ( void ); |
---|
| 74 | |
---|
| 75 | #endif /* STDLIB_H */ |
---|