1 /* stdlib.h */
2 
3 /*
4  * Copyright (c) 2011-2014 Wind River Systems, Inc.
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_STDLIB_H_
10 #define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_STDLIB_H_
11 
12 #include <stddef.h>
13 #include <limits.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 unsigned long strtoul(const char *nptr, char **endptr, int base);
20 long strtol(const char *nptr, char **endptr, int base);
21 unsigned long long strtoull(const char *nptr, char **endptr, int base);
22 long long strtoll(const char *nptr, char **endptr, int base);
23 int atoi(const char *s);
24 
25 void *malloc(size_t size);
26 void *aligned_alloc(size_t alignment, size_t size); /* From C11 */
27 
28 void free(void *ptr);
29 void *calloc(size_t nmemb, size_t size);
30 void *realloc(void *ptr, size_t size);
31 void *reallocarray(void *ptr, size_t nmemb, size_t size);
32 
33 void *bsearch(const void *key, const void *array,
34 	      size_t count, size_t size,
35 	      int (*cmp)(const void *key, const void *element));
36 
37 void qsort_r(void *base, size_t nmemb, size_t size,
38 	     int (*compar)(const void *, const void *, void *), void *arg);
39 void qsort(void *base, size_t nmemb, size_t size,
40 	   int (*compar)(const void *, const void *));
41 
42 #define EXIT_SUCCESS 0
43 #define EXIT_FAILURE 1
44 void _exit(int status);
exit(int status)45 static inline void exit(int status)
46 {
47 	_exit(status);
48 }
49 void abort(void);
50 
51 #ifdef CONFIG_MINIMAL_LIBC_RAND
52 #define RAND_MAX INT_MAX
53 int rand_r(unsigned int *seed);
54 int rand(void);
55 void srand(unsigned int seed);
56 #endif /* CONFIG_MINIMAL_LIBC_RAND */
57 
abs(int __n)58 static inline int abs(int __n)
59 {
60 	return (__n < 0) ? -__n : __n;
61 }
62 
labs(long __n)63 static inline long labs(long __n)
64 {
65 	return (__n < 0L) ? -__n : __n;
66 }
67 
llabs(long long __n)68 static inline long long llabs(long long __n)
69 {
70 	return (__n < 0LL) ? -__n : __n;
71 }
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif  /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_STDLIB_H_ */
78