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