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.

stdlib.h 1.8KB

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