Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / stdlib.h
1 #ifndef STDLIB_H
2 #define STDLIB_H
3
4 FILE_LICENCE ( GPL2_OR_LATER );
5
6 #include <stdint.h>
7 #include <assert.h>
8
9 /*****************************************************************************
10  *
11  * Numeric parsing
12  *
13  ****************************************************************************
14  */
15
16 static inline int strtoul_base ( const char **pp, int base )
17 {
18         const char *p = *pp;
19
20         if ( base == 0 ) {
21                 base = 10;
22                 if ( *p == '0' ) {
23                         p++;
24                         base = 8;
25                         if ( ( *p | 0x20 ) == 'x' ) {
26                                 p++;
27                                 base = 16;
28                         }
29                 }
30         }
31
32         *pp = p;
33
34         return base;
35 }
36
37 extern unsigned int strtoul_charval ( unsigned int charval );
38 extern unsigned long strtoul ( const char *p, char **endp, int base );
39 extern unsigned long long strtoull ( const char *p, char **endp, int base );
40
41
42 /*****************************************************************************
43  *
44  * Memory allocation
45  *
46  ****************************************************************************
47  */
48
49 extern void * __malloc malloc ( size_t size );
50 extern void * realloc ( void *old_ptr, size_t new_size );
51 extern void free ( void *ptr );
52 extern void * __malloc zalloc ( size_t len );
53
54 /**
55  * Allocate cleared memory
56  *
57  * @v nmemb             Number of members
58  * @v size              Size of each member
59  * @ret ptr             Allocated memory
60  *
61  * Allocate memory as per malloc(), and zero it.
62  *
63  * This is implemented as a static inline, with the body of the
64  * function in zalloc(), since in most cases @c nmemb will be 1 and
65  * doing the multiply is just wasteful.
66  */
67 static inline void * __malloc calloc ( size_t nmemb, size_t size ) {
68         return zalloc ( nmemb * size );
69 }
70
71 /*****************************************************************************
72  *
73  * Random number generation
74  *
75  ****************************************************************************
76  */
77
78 extern long int random ( void );
79 extern void srandom ( unsigned int seed );
80
81 static inline int rand ( void ) {
82         return random();
83 }
84
85 static inline void srand ( unsigned int seed ) {
86         srandom ( seed );
87 }
88
89 /*****************************************************************************
90  *
91  * Miscellaneous
92  *
93  ****************************************************************************
94  */
95
96 static inline __attribute__ (( always_inline )) int abs ( int value ) {
97         return __builtin_abs ( value );
98 }
99
100 extern int system ( const char *command );
101 extern __asmcall int main ( void );
102
103 #endif /* STDLIB_H */