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. Returns the value actually
154  * set -- this value is capped to avoid trashing the stack.
155  */
156 size_t __set_heap_limit(size_t limit);
157 
158 /* Return the maximum safe heap size to avoid stack collision. */
159 size_t __get_heap_max_safe_size(void);
160 
161 /* Return heap bytes in use, including overhead for heap data structures in
162  the existing allocations. */
163 size_t __heap_bytes_used();
164 
165 /* Return heap bytes available for future allocations. This does not take into
166  account the overhead of the heap itself, which depends on how many
167  allocations are made.*/
168 size_t __heap_bytes_free();
169 
170 #ifdef _MOS_SOURCE
171 
172 #define heap_limit __heap_limit
173 #define set_heap_limit __set_heap_limit
174 #define heap_bytes_used __heap_bytes_used
175 #define heap_bytes_free __heap_bytes_free
176 
177 #endif // _MOS_SOURCE
178 
179 // Communication with the environment
180 
181 _Noreturn void abort(void);
182 int atexit(void (*func)(void));
183 int at_quick_exit(void (*func)(void));
184 _Noreturn void exit(int status);
185 __attribute__((leaf)) _Noreturn void _Exit(int status);
186 char *getenv(const char *name);
187 _Noreturn void quick_exit(int status);
188 int system(const char *string);
189 
190 // Sorting and searching utilities
191 
192 void *bsearch(const void *key, const void *base, size_t nmemb, size_t size,
193  int (*compar)(const void *, const void *));
194 void qsort(void *base, size_t nmemb, size_t size,
195  int (*compar)(const void *, const void *));
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 
201 #endif // not _STDLIB_H_
void * realloc(void *ptr, size_t size)
void srand(unsigned seed)
void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
int atoi(const char *s)
div_t div(int numer, int denom)
void * bsearch(const void *key, const void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
long long atoll(const char *nptr)
unsigned char _strtouc(const char *__restrict__ nptr, char **__restrict endptr, int base)
void * calloc(size_t nmemb, size_t size)
ldiv_t ldiv(long numer, long denom)
long long llabs(long long i)
void * malloc(size_t size)
_Noreturn void abort(void)
int atexit(void(*func)(void))
long atol(const char *s)
int system(const char *string)
long strtol(const char *__restrict__ nptr, char **__restrict endptr, int base)
unsigned long strtoul(const char *__restrict__ nptr, char **__restrict endptr, int base)
_Noreturn void quick_exit(int status)
unsigned int _strtoui(const char *__restrict__ nptr, char **__restrict endptr, int base)
_Noreturn void exit(int status)
unsigned long long strtoull(const char *__restrict__ nptr, char **__restrict endptr, int base)
char * getenv(const char *name)
lldiv_t lldiv(long long numer, long long denom)
long labs(long i)
int at_quick_exit(void(*func)(void))
int rand(void)
int _strtoi(const char *__restrict__ nptr, char **__restrict endptr, int base)
signed char _strtosc(const char *__restrict__ nptr, char **__restrict endptr, int base)
int abs(int i)
long long strtoll(const char *__restrict__ nptr, char **__restrict endptr, int base)
void * aligned_alloc(size_t alignment, size_t size)
void free(void *ptr)
unsigned size
Definition: neslib.h:185
Definition: stdlib.h:28
int quot
Definition: stdlib.h:29
int rem
Definition: stdlib.h:30
Definition: stdlib.h:34
long rem
Definition: stdlib.h:36
long quot
Definition: stdlib.h:35
Definition: stdlib.h:40
long long rem
Definition: stdlib.h:42
long long quot
Definition: stdlib.h:41