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