2005-04-30 15:48:48 +02:00
|
|
|
#ifndef STDLIB_H
|
|
|
|
#define STDLIB_H
|
|
|
|
|
2015-03-02 14:29:46 +01:00
|
|
|
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
2009-05-01 16:41:06 +02:00
|
|
|
|
2007-01-19 01:39:12 +01:00
|
|
|
#include <stdint.h>
|
2007-01-19 03:02:59 +01:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Numeric parsing
|
|
|
|
*
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
2007-01-19 01:39:12 +01:00
|
|
|
|
2015-02-19 17:00:01 +01:00
|
|
|
extern unsigned long strtoul ( const char *string, char **endp, int base );
|
|
|
|
extern unsigned long long strtoull ( const char *string, char **endp,
|
|
|
|
int base );
|
2007-01-19 03:02:59 +01:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Memory allocation
|
|
|
|
*
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
2007-08-20 20:29:50 +02:00
|
|
|
extern void * __malloc malloc ( size_t size );
|
2007-01-19 03:02:59 +01:00
|
|
|
extern void * realloc ( void *old_ptr, size_t new_size );
|
2006-12-02 21:10:21 +01:00
|
|
|
extern void free ( void *ptr );
|
2007-08-20 20:29:50 +02:00
|
|
|
extern void * __malloc zalloc ( size_t len );
|
2007-01-18 13:54:18 +01:00
|
|
|
|
2006-12-02 21:10:21 +01: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 13:54:18 +01:00
|
|
|
* This is implemented as a static inline, with the body of the
|
2007-06-11 22:36:10 +02:00
|
|
|
* function in zalloc(), since in most cases @c nmemb will be 1 and
|
2007-01-18 13:54:18 +01:00
|
|
|
* doing the multiply is just wasteful.
|
2006-12-02 21:10:21 +01:00
|
|
|
*/
|
2007-08-20 20:29:50 +02:00
|
|
|
static inline void * __malloc calloc ( size_t nmemb, size_t size ) {
|
2007-06-11 22:36:10 +02:00
|
|
|
return zalloc ( nmemb * size );
|
2006-12-02 21:10:21 +01:00
|
|
|
}
|
2005-04-30 15:48:48 +02:00
|
|
|
|
2007-01-19 03:02:59 +01: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
|
|
|
|
*
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
2014-01-07 04:53:56 +01:00
|
|
|
static inline __attribute__ (( always_inline )) int abs ( int value ) {
|
|
|
|
return __builtin_abs ( value );
|
|
|
|
}
|
|
|
|
|
2007-01-19 03:02:59 +01:00
|
|
|
extern int system ( const char *command );
|
2008-11-19 01:18:32 +01:00
|
|
|
extern __asmcall int main ( void );
|
2007-01-19 03:02:59 +01:00
|
|
|
|
2005-04-30 15:48:48 +02:00
|
|
|
#endif /* STDLIB_H */
|