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.1KB

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