You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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