2005-04-30 13:48:48 +00:00
|
|
|
#ifndef STDLIB_H
|
|
|
|
#define STDLIB_H
|
|
|
|
|
2007-01-19 00:39:12 +00:00
|
|
|
#include <stdint.h>
|
2007-01-19 02:02:59 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Numeric parsing
|
|
|
|
*
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
2007-01-19 00:39:12 +00:00
|
|
|
|
2006-04-30 11:45:38 +00:00
|
|
|
extern unsigned long strtoul ( const char *p, char **endp, int base );
|
2007-01-19 02:02:59 +00:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Memory allocation
|
|
|
|
*
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
2006-12-02 20:10:21 +00:00
|
|
|
extern void * malloc ( size_t size );
|
2007-01-19 02:02:59 +00:00
|
|
|
extern void * realloc ( void *old_ptr, size_t new_size );
|
2006-12-02 20:10:21 +00:00
|
|
|
extern void free ( void *ptr );
|
2007-06-11 20:36:10 +00:00
|
|
|
extern void * zalloc ( size_t len );
|
2007-01-18 12:54:18 +00:00
|
|
|
|
2006-12-02 20:10:21 +00:00
|
|
|
/**
|
|
|
|
* Allocate cleared memory
|
|
|
|
*
|
|
|
|
* @v nmemb Number of members
|
|
|
|
* @v size Size of each member
|
|
|
|
* @ret ptr Allocated memory
|
|
|
|
*
|
|
|
|
* Allocate memory as per malloc(), and zero it.
|
|
|
|
*
|
2007-01-18 12:54:18 +00:00
|
|
|
* This is implemented as a static inline, with the body of the
|
2007-06-11 20:36:10 +00:00
|
|
|
* function in zalloc(), since in most cases @c nmemb will be 1 and
|
2007-01-18 12:54:18 +00:00
|
|
|
* doing the multiply is just wasteful.
|
2006-12-02 20:10:21 +00:00
|
|
|
*/
|
|
|
|
static inline void * calloc ( size_t nmemb, size_t size ) {
|
2007-06-11 20:36:10 +00:00
|
|
|
return zalloc ( nmemb * size );
|
2006-12-02 20:10:21 +00:00
|
|
|
}
|
2005-04-30 13:48:48 +00:00
|
|
|
|
2007-01-19 02:02:59 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Random number generation
|
|
|
|
*
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern long int random ( void );
|
|
|
|
extern void srandom ( unsigned int seed );
|
|
|
|
|
|
|
|
static inline int rand ( void ) {
|
|
|
|
return random();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void srand ( unsigned int seed ) {
|
|
|
|
srandom ( seed );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Miscellaneous
|
|
|
|
*
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern int system ( const char *command );
|
|
|
|
|
2005-04-30 13:48:48 +00:00
|
|
|
#endif /* STDLIB_H */
|