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 );
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 */
46static 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
57extern long int random ( void );
58extern void srandom ( unsigned int seed );
59
60static inline int rand ( void ) {
61 return random();
62}
63
64static inline void srand ( unsigned int seed ) {
65 srandom ( seed );
66}
67
68/*****************************************************************************
69 *
70 * Miscellaneous
71 *
72 ****************************************************************************
73 */
74
75static inline __attribute__ (( always_inline )) int abs ( int value ) {
76 return __builtin_abs ( value );
77}
78
79extern int system ( const char *command );
80extern __asmcall int main ( void );
81
82#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:598
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:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#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:64
static int rand(void)
Definition stdlib.h:60
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition string.c:485
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:662
void * realloc(void *old_ptr, size_t new_size)
Reallocate memory.
Definition malloc.c:607
void *__malloc malloc(size_t size)
Allocate memory.
Definition malloc.c:621
__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:520
static void *__malloc calloc(size_t nmemb, size_t size)
Allocate cleared memory.
Definition stdlib.h:46
void srandom(unsigned int seed)
Seed the pseudo-random number generator.
Definition random.c:21
A command-line command.
Definition command.h:10