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 #include <zephyr/toolchain.h>
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 unsigned long strtoul(const char *nptr, char **endptr, int base);
22 long strtol(const char *nptr, char **endptr, int base);
23 unsigned long long strtoull(const char *nptr, char **endptr, int base);
24 long long strtoll(const char *nptr, char **endptr, int base);
25 int atoi(const char *s);
26
27 void *malloc(size_t size);
28 void *aligned_alloc(size_t alignment, size_t size); /* From C11 */
29
30 void free(void *ptr);
31 void *calloc(size_t nmemb, size_t size);
32 void *realloc(void *ptr, size_t size);
33 void *reallocarray(void *ptr, size_t nmemb, size_t size);
34
35 void *bsearch(const void *key, const void *array,
36 size_t count, size_t size,
37 int (*cmp)(const void *key, const void *element));
38
39 void qsort_r(void *base, size_t nmemb, size_t size,
40 int (*compar)(const void *, const void *, void *), void *arg);
41 void qsort(void *base, size_t nmemb, size_t size,
42 int (*compar)(const void *, const void *));
43
44 #define EXIT_SUCCESS 0
45 #define EXIT_FAILURE 1
46 FUNC_NORETURN void _exit(int status);
exit(int status)47 FUNC_NORETURN static inline void exit(int status)
48 {
49 _exit(status);
50 }
51 FUNC_NORETURN void abort(void);
52
53 #ifdef CONFIG_MINIMAL_LIBC_RAND
54 #define RAND_MAX INT_MAX
55 int rand_r(unsigned int *seed);
56 int rand(void);
57 void srand(unsigned int seed);
58 #endif /* CONFIG_MINIMAL_LIBC_RAND */
59
abs(int __n)60 static inline int abs(int __n)
61 {
62 return (__n < 0) ? -__n : __n;
63 }
64
labs(long __n)65 static inline long labs(long __n)
66 {
67 return (__n < 0L) ? -__n : __n;
68 }
69
llabs(long long __n)70 static inline long long llabs(long long __n)
71 {
72 return (__n < 0LL) ? -__n : __n;
73 }
74
75 char *getenv(const char *name);
76 #if _POSIX_C_SOURCE >= 200112L
77 int setenv(const char *name, const char *val, int overwrite);
78 int unsetenv(const char *name);
79 #endif
80
81 #ifdef _BSD_SOURCE
82 int getenv_r(const char *name, char *buf, size_t len);
83 #endif
84
85 #ifdef __cplusplus
86 }
87 #endif
88
89 #endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_STDLIB_H_ */
90