llvm-mos-sdk
stdlib.h
Go to the documentation of this file.
1 #ifndef _STDLIB_H_
2 #define _STDLIB_H_
3 
4 #include <stddef.h>
5 
6 #ifndef __LLVM_MOS_SDK
7 #define __LLVM_MOS_SDK 1
8 #endif
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #define EXIT_SUCCESS 0
15 #define EXIT_FAILURE 1
16 
17 #define RAND_MAX 32767
18 
19 #define MB_CUR_MAX ((size_t)1)
20 
21 int abs(int i);
22 long labs(long i);
23 long long llabs(long long i);
24 
25 int atoi(const char *s);
26 long atol(const char *s);
27 
28 typedef struct {
29  int quot;
30  int rem;
31 } div_t;
32 div_t div(int numer, int denom);
33 
34 typedef struct {
35  long quot;
36  long rem;
37 } ldiv_t;
38 ldiv_t ldiv(long numer, long denom);
39 
40 typedef struct {
41  long long quot;
42  long long rem;
43 } lldiv_t;
44 lldiv_t lldiv(long long numer, long long denom);
45 
46 int atoi(const char *nptr);
47 long atol(const char *nptr);
48 long long atoll(const char *nptr);
49 
50 long strtol(const char *__restrict__ nptr, char **__restrict endptr, int base);
51 long long strtoll(const char *__restrict__ nptr, char **__restrict endptr,
52  int base);
53 unsigned long strtoul(const char *__restrict__ nptr, char **__restrict endptr,
54  int base);
55 unsigned long long strtoull(const char *__restrict__ nptr,
56  char **__restrict endptr, int base);
57 
58 // Non-standard strtox functions for smaller types.
59 signed char _strtosc(const char *__restrict__ nptr, char **__restrict endptr,
60  int base);
61 unsigned char _strtouc(const char *__restrict__ nptr, char **__restrict endptr,
62  int base);
63 int _strtoi(const char *__restrict__ nptr, char **__restrict endptr, int base);
64 unsigned int _strtoui(const char *__restrict__ nptr, char **__restrict endptr,
65  int base);
66 
67 int rand(void);
68 void srand(unsigned seed);
69 
70 // clang-format off
124 // clang-format on
125 
126 void *aligned_alloc(size_t alignment, size_t size);
127 void *calloc(size_t nmemb, size_t size);
128 void free(void *ptr);
129 void *malloc(size_t size);
130 void *realloc(void *ptr, size_t size);
131 
132 /* The maximum heap size can be limited in the following ways:
133 1. If no heap allocation has been made yet, the heap limit can be set to any
134  size greater than the implementation-defined minimum block size. This actual
135  minimum is only a few bytes, but for practical purposes if you are using the
136  heap, you should at least plan on using 100's or 1000's of bytes.
137 2. If an allocation is made prior to setting the heap limit, the initial limit
138  is set to the value of the symbol `__heap_default_limit`. The actual limit
139  may depend on the available address space of the target platform.
140 3. After the first allocation has been made, the heap may only increase in size.
141  Any attempt to decrease the size of the heap limit will be ignored.
142 
143 Increasing the heap limit does not do any validation to ensure the heap will not
144 collide with the stack. You must leave enough space for whatever stack usage
145 your program needs.
146 */
147 
148 /* Return the current maximium size of the heap. */
149 size_t __heap_limit();
150 
151 /* Set the maximum size of the heap. Note the limitations above. */
152 /* Setting the heap limit implicitly allocates the heap. Don't call this
153  function if you aren't going to use the heap. */
154 void __set_heap_limit(size_t limit);
155 
156 /* Return heap bytes in use, including overhead for heap data structures in
157  the existing allocations. */
158 size_t __heap_bytes_used();
159 
160 /* Return heap bytes available for future allocations. This does not take into
161  account the overhead of the heap itself, which depends on how many
162  allocations are made.*/
163 size_t __heap_bytes_free();
164 
165 #ifdef _MOS_SOURCE
166 
167 #define heap_limit __heap_limit
168 #define set_heap_limit __set_heap_limit
169 #define heap_bytes_used __heap_bytes_used
170 #define heap_bytes_free __heap_bytes_free
171 
172 #endif // _MOS_SOURCE
173 
174 // Communication with the environment
175 
176 _Noreturn void abort(void);
177 int atexit(void (*func)(void));
178 int at_quick_exit(void (*func)(void));
179 _Noreturn void exit(int status);
180 __attribute__((leaf)) _Noreturn void _Exit(int status);
181 char *getenv(const char *name);
182 _Noreturn void quick_exit(int status);
183 int system(const char *string);
184 
185 // Sorting and searching utilities
186 
187 void *bsearch(const void *key, const void *base, size_t nmemb, size_t size,
188  int (*compar)(const void *, const void *));
189 void qsort(void *base, size_t nmemb, size_t size,
190  int (*compar)(const void *, const void *));
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif // not _STDLIB_H_
atol
long atol(const char *s)
atoll
long long atoll(const char *nptr)
div_t::rem
int rem
Definition: stdlib.h:30
exit
_Noreturn void exit(int status)
div_t
Definition: stdlib.h:28
lldiv_t::rem
long long rem
Definition: stdlib.h:42
abs
int abs(int i)
bsearch
void * bsearch(const void *key, const void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
llabs
long long llabs(long long i)
abort
_Noreturn void abort(void)
strtoul
unsigned long strtoul(const char *__restrict__ nptr, char **__restrict endptr, int base)
strtoll
long long strtoll(const char *__restrict__ nptr, char **__restrict endptr, int base)
atoi
int atoi(const char *s)
strtol
long strtol(const char *__restrict__ nptr, char **__restrict endptr, int base)
div
div_t div(int numer, int denom)
lldiv_t
Definition: stdlib.h:40
system
int system(const char *string)
malloc
void * malloc(size_t size)
free
void free(void *ptr)
lldiv
lldiv_t lldiv(long long numer, long long denom)
lldiv_t::quot
long long quot
Definition: stdlib.h:41
quick_exit
_Noreturn void quick_exit(int status)
srand
void srand(unsigned seed)
qsort
void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
labs
long labs(long i)
_strtoi
int _strtoi(const char *__restrict__ nptr, char **__restrict endptr, int base)
atexit
int atexit(void(*func)(void))
at_quick_exit
int at_quick_exit(void(*func)(void))
size
unsigned size
Definition: neslib.h:185
aligned_alloc
void * aligned_alloc(size_t alignment, size_t size)
_strtosc
signed char _strtosc(const char *__restrict__ nptr, char **__restrict endptr, int base)
ldiv_t::quot
long quot
Definition: stdlib.h:35
strtoull
unsigned long long strtoull(const char *__restrict__ nptr, char **__restrict endptr, int base)
calloc
void * calloc(size_t nmemb, size_t size)
_strtouc
unsigned char _strtouc(const char *__restrict__ nptr, char **__restrict endptr, int base)
ldiv_t::rem
long rem
Definition: stdlib.h:36
rand
int rand(void)
ldiv
ldiv_t ldiv(long numer, long denom)
realloc
void * realloc(void *ptr, size_t size)
_strtoui
unsigned int _strtoui(const char *__restrict__ nptr, char **__restrict endptr, int base)
getenv
char * getenv(const char *name)
ldiv_t
Definition: stdlib.h:34
div_t::quot
int quot
Definition: stdlib.h:29