1#ifndef _LIBC_STDLIB_H
2#define _LIBC_STDLIB_H
3
4#include <stddef.h>
5#include <sys/cdefs.h>
6#include <sys/environ.h>
7#include <sys/types.h>
8
9__BEGIN_DECLS
10
11#ifndef NOMINMAX
12#ifndef max
13#define max(a, b) \
14 ({ __typeof__ (a) _a = (a); \
15 __typeof__ (b) _b = (b); \
16 _a > _b ? _a : _b; })
17#endif /* max */
18
19#ifndef min
20#define min(a, b) \
21 ({ __typeof__ (a) _a = (a); \
22 __typeof__ (b) _b = (b); \
23 _a < _b ? _a : _b; })
24#endif /* min */
25#endif /* NOMINMAX */
26
27static inline int abs(int i)
28{
29 return i < 0 ? -i : i;
30}
31
32/* malloc */
33extern void* malloc(size_t);
34extern void free(void*);
35extern void* calloc(size_t, size_t);
36extern void* realloc(void*, size_t);
37
38/* tools */
39int atoi(const char* s);
40
41/* exit */
42void abort() __attribute__((noreturn));
43void exit(int status) __attribute__((noreturn));
44
45/* pts */
46int posix_openpt(int flags);
47int ptsname_r(int fd, char* buf, size_t buflen);
48char* ptsname(int fd);
49
50/* env */
51int putenv(char* string);
52char* getenv(const char* name);
53int setenv(const char* name, const char* value, int overwrite);
54int unsetenv(const char* name);
55
56__END_DECLS
57
58#endif // _LIBC_STDLIB_H