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 2.2KB

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