Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

stdlib.h 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. extern __asmcall int main ( void );
  60. #endif /* STDLIB_H */