iPXE
stdlib.h
Go to the documentation of this file.
1 #ifndef STDLIB_H
2 #define STDLIB_H
3 
4 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5 
6 #include <stdint.h>
7 #include <assert.h>
8 
9 /*****************************************************************************
10  *
11  * Numeric parsing
12  *
13  ****************************************************************************
14  */
15 
16 extern unsigned long strtoul ( const char *string, char **endp, int base );
17 extern unsigned long long strtoull ( const char *string, char **endp,
18  int base );
19 
20 /*****************************************************************************
21  *
22  * Memory allocation
23  *
24  ****************************************************************************
25  */
26 
27 extern void * __malloc malloc ( size_t size );
28 extern void * realloc ( void *old_ptr, size_t new_size );
29 extern void free ( void *ptr );
30 extern void * __malloc zalloc ( size_t len );
31 
32 /**
33  * Allocate cleared memory
34  *
35  * @v nmemb Number of members
36  * @v size Size of each member
37  * @ret ptr Allocated memory
38  *
39  * Allocate memory as per malloc(), and zero it.
40  *
41  * This is implemented as a static inline, with the body of the
42  * function in zalloc(), since in most cases @c nmemb will be 1 and
43  * doing the multiply is just wasteful.
44  */
45 static inline void * __malloc calloc ( size_t nmemb, size_t size ) {
46  return zalloc ( nmemb * size );
47 }
48 
49 /*****************************************************************************
50  *
51  * Random number generation
52  *
53  ****************************************************************************
54  */
55 
56 extern long int random ( void );
57 extern void srandom ( unsigned int seed );
58 
59 static inline int rand ( void ) {
60  return random();
61 }
62 
63 static inline void srand ( unsigned int seed ) {
64  srandom ( seed );
65 }
66 
67 /*****************************************************************************
68  *
69  * Miscellaneous
70  *
71  ****************************************************************************
72  */
73 
74 static inline __attribute__ (( always_inline )) int abs ( int value ) {
75  return __builtin_abs ( value );
76 }
77 
78 extern int system ( const char *command );
79 extern __asmcall int main ( void );
80 
81 #endif /* STDLIB_H */
void *__malloc zalloc(size_t len)
Allocate cleared memory.
Definition: malloc.c:624
void free(void *ptr)
Free memory.
Definition: malloc.c:604
A command-line command.
Definition: command.h:9
void srandom(unsigned int seed)
Seed the pseudo-random number generator.
Definition: random.c:20
static const void * base
Base address.
Definition: crypto.h:335
static __attribute__((always_inline)) int abs(int value)
Definition: stdlib.h:74
#define abs(x)
Definition: ath.h:44
long int random(void)
Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
Definition: random.c:31
#define __asmcall
Declare a function with standard calling conventions.
Definition: compiler.h:15
Assertions.
static int rand(void)
Definition: stdlib.h:59
static void srand(unsigned int seed)
Definition: stdlib.h:63
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:471
static void *__malloc calloc(size_t nmemb, size_t size)
Allocate cleared memory.
Definition: stdlib.h:45
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
unsigned long long strtoull(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:506
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
uint32_t len
Length.
Definition: ena.h:14
#define __malloc
Declare a pointer returned by a function as a unique memory address as returned by malloc-type functi...
Definition: compiler.h:598
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
int system(const char *command)
Execute command line.
Definition: exec.c:287
void *__malloc malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
void * realloc(void *old_ptr, size_t new_size)
Reallocate memory.
Definition: malloc.c:521
__asmcall int main(void)
Main entry point.
Definition: main.c:28