iPXE
stdlib.h
Go to the documentation of this file.
00001 #ifndef STDLIB_H
00002 #define STDLIB_H
00003 
00004 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00005 
00006 #include <stdint.h>
00007 #include <assert.h>
00008 
00009 /*****************************************************************************
00010  *
00011  * Numeric parsing
00012  *
00013  ****************************************************************************
00014  */
00015 
00016 extern unsigned long strtoul ( const char *string, char **endp, int base );
00017 extern unsigned long long strtoull ( const char *string, char **endp,
00018                                      int base );
00019 
00020 /*****************************************************************************
00021  *
00022  * Memory allocation
00023  *
00024  ****************************************************************************
00025  */
00026 
00027 extern void * __malloc malloc ( size_t size );
00028 extern void * realloc ( void *old_ptr, size_t new_size );
00029 extern void free ( void *ptr );
00030 extern void * __malloc zalloc ( size_t len );
00031 
00032 /**
00033  * Allocate cleared memory
00034  *
00035  * @v nmemb             Number of members
00036  * @v size              Size of each member
00037  * @ret ptr             Allocated memory
00038  *
00039  * Allocate memory as per malloc(), and zero it.
00040  *
00041  * This is implemented as a static inline, with the body of the
00042  * function in zalloc(), since in most cases @c nmemb will be 1 and
00043  * doing the multiply is just wasteful.
00044  */
00045 static inline void * __malloc calloc ( size_t nmemb, size_t size ) {
00046         return zalloc ( nmemb * size );
00047 }
00048 
00049 /*****************************************************************************
00050  *
00051  * Random number generation
00052  *
00053  ****************************************************************************
00054  */
00055 
00056 extern long int random ( void );
00057 extern void srandom ( unsigned int seed );
00058 
00059 static inline int rand ( void ) {
00060         return random();
00061 }
00062 
00063 static inline void srand ( unsigned int seed ) {
00064         srandom ( seed );
00065 }
00066 
00067 /*****************************************************************************
00068  *
00069  * Miscellaneous
00070  *
00071  ****************************************************************************
00072  */
00073 
00074 static inline __attribute__ (( always_inline )) int abs ( int value ) {
00075         return __builtin_abs ( value );
00076 }
00077 
00078 extern int system ( const char *command );
00079 extern __asmcall int main ( void );
00080 
00081 #endif /* STDLIB_H */