Remove building with NOCRYPTO option
[minix.git] / minix / llvm / include / common / util / stdlib.h
blob19a3c6d81210aae23c30b373c61abee5760131ad
1 #ifndef _UTIL_STDLIB_H
2 #define _UTIL_STDLIB_H
4 #include "util_def.h"
6 #include <string.h>
8 typedef struct util_stdlib_s {
9 int id;
10 char *name;
11 unsigned long flags;
12 } util_stdlib_t;
14 typedef enum util_stdlib_id_e {
15 STDLIB_ACCEPT = 0,
16 STDLIB_ACCEPT4,
17 STDLIB_BIND,
18 STDLIB_BRK,
19 STDLIB_CALLOC,
20 STDLIB_EPOLL_CREATE,
21 STDLIB_EPOLL_CREATE1,
22 STDLIB_EPOLL_WAIT,
23 STDLIB_FREE,
24 STDLIB_GETSOCKOPT,
25 STDLIB_KILL,
26 STDLIB_LISTEN,
27 STDLIB_MALLOC,
28 STDLIB_MEMALIGN,
29 STDLIB_MMAP,
30 STDLIB_MMAP64,
31 STDLIB_MUNMAP,
32 STDLIB_POLL,
33 STDLIB_POSIX_MEMALIGN,
34 STDLIB_PPOLL,
35 STDLIB_PTHREAD_COND_WAIT,
36 STDLIB_PTHREAD_COND_TIMEDWAIT,
37 STDLIB_PTHREAD_JOIN,
38 STDLIB_READ,
39 STDLIB_REALLOC,
40 STDLIB_RECV,
41 STDLIB_RECVFROM,
42 STDLIB_RECVMSG,
43 STDLIB_SBRK,
44 STDLIB_SELECT,
45 STDLIB_SEMOP,
46 STDLIB_SEMTIMEDOP,
47 STDLIB_SETSOCKOPT,
48 STDLIB_SHMAT,
49 STDLIB_SHMDT,
50 STDLIB_SIGSUSPEND,
51 STDLIB_SIGTIMEDWAIT,
52 STDLIB_SIGWAITINFO,
53 STDLIB_SLEEP,
54 STDLIB_SOCKET,
55 STDLIB_USLEEP,
56 STDLIB_VALLOC,
57 STDLIB_WAITPID,
58 __NUM_STDLIBS_IDS
59 } util_stdlib_id_t;
61 typedef enum util_stdlib_flag_e {
62 STLIB_BLOCK_EXT = 0,
63 STLIB_BLOCK_INT,
64 __NUM_STDLIBS_FLAGS
65 } util_stdlib_flag_t;
66 #define _UTIL_STLIB_FLAGS_STR "ei"
68 #define _UTIL_STLIB_FLAG(F) (1 << (F))
69 #define _UTIL_STLIB_BLOCK_MASK \
70 (_UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)|_UTIL_STLIB_FLAG(STLIB_BLOCK_INT))
72 #define _UTIL_STLIB_FLAGS_STR_BUFF_SIZE (__NUM_STDLIBS_FLAGS+1)
73 #define _UTIL_STLIB_FLAG_C(F, E) \
74 (((F) & _UTIL_STLIB_FLAG(E)) ? _UTIL_STLIB_FLAGS_STR[E] : '-')
76 #define _UTIL_STDLIB_DEF(ID, N, F) { (ID), (N), (F) }
77 #define _UTIL_STDLIBS_INITIALIZER { \
78 _UTIL_STDLIB_DEF(STDLIB_ACCEPT, "accept", _UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)), \
79 _UTIL_STDLIB_DEF(STDLIB_ACCEPT4, "accept4", _UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)), \
80 _UTIL_STDLIB_DEF(STDLIB_BIND, "bind", 0), \
81 _UTIL_STDLIB_DEF(STDLIB_BRK, "brk", 0), \
82 _UTIL_STDLIB_DEF(STDLIB_CALLOC, "calloc", 0), \
83 _UTIL_STDLIB_DEF(STDLIB_EPOLL_CREATE, "epoll_create", 0), \
84 _UTIL_STDLIB_DEF(STDLIB_EPOLL_CREATE1, "epoll_create1", 0), \
85 _UTIL_STDLIB_DEF(STDLIB_EPOLL_WAIT, "epoll_wait", _UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)), \
86 _UTIL_STDLIB_DEF(STDLIB_FREE, "free", 0), \
87 _UTIL_STDLIB_DEF(STDLIB_GETSOCKOPT, "getsockopt", 0), \
88 _UTIL_STDLIB_DEF(STDLIB_KILL, "kill", 0), \
89 _UTIL_STDLIB_DEF(STDLIB_LISTEN, "listen", 0), \
90 _UTIL_STDLIB_DEF(STDLIB_MALLOC, "malloc", 0), \
91 _UTIL_STDLIB_DEF(STDLIB_MEMALIGN, "memalign", 0), \
92 _UTIL_STDLIB_DEF(STDLIB_MMAP, "mmap", 0), \
93 _UTIL_STDLIB_DEF(STDLIB_MMAP64, "mmap64", 0), \
94 _UTIL_STDLIB_DEF(STDLIB_MUNMAP, "munmap", 0), \
95 _UTIL_STDLIB_DEF(STDLIB_POLL, "poll", _UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)), \
96 _UTIL_STDLIB_DEF(STDLIB_POSIX_MEMALIGN, "posix_memalign", 0), \
97 _UTIL_STDLIB_DEF(STDLIB_PPOLL, "ppoll", _UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)), \
98 _UTIL_STDLIB_DEF(STDLIB_PTHREAD_COND_WAIT, "pthread_cond_wait", _UTIL_STLIB_FLAG(STLIB_BLOCK_INT)), \
99 _UTIL_STDLIB_DEF(STDLIB_PTHREAD_COND_TIMEDWAIT, "pthread_cond_timedwait", _UTIL_STLIB_FLAG(STLIB_BLOCK_INT)), \
100 _UTIL_STDLIB_DEF(STDLIB_PTHREAD_JOIN, "pthread_join", _UTIL_STLIB_FLAG(STLIB_BLOCK_INT)), \
101 _UTIL_STDLIB_DEF(STDLIB_READ, "read", _UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)), \
102 _UTIL_STDLIB_DEF(STDLIB_REALLOC, "realloc", 0), \
103 _UTIL_STDLIB_DEF(STDLIB_RECV, "recv", _UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)), \
104 _UTIL_STDLIB_DEF(STDLIB_RECVFROM, "recvfrom", _UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)), \
105 _UTIL_STDLIB_DEF(STDLIB_RECVMSG, "recvsmg", _UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)), \
106 _UTIL_STDLIB_DEF(STDLIB_SBRK, "sbrk", 0), \
107 _UTIL_STDLIB_DEF(STDLIB_SELECT, "select", _UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)), \
108 _UTIL_STDLIB_DEF(STDLIB_SEMOP, "semop", _UTIL_STLIB_FLAG(STLIB_BLOCK_INT)), \
109 _UTIL_STDLIB_DEF(STDLIB_SEMTIMEDOP, "semtimedop", _UTIL_STLIB_FLAG(STLIB_BLOCK_INT)), \
110 _UTIL_STDLIB_DEF(STDLIB_SETSOCKOPT, "setsockopt", 0), \
111 _UTIL_STDLIB_DEF(STDLIB_SHMAT, "shmat", 0), \
112 _UTIL_STDLIB_DEF(STDLIB_SHMDT, "shmdt", 0), \
113 _UTIL_STDLIB_DEF(STDLIB_SIGSUSPEND, "sigsuspend", _UTIL_STLIB_FLAG(STLIB_BLOCK_INT)), \
114 _UTIL_STDLIB_DEF(STDLIB_SIGTIMEDWAIT, "sigtimedwait", _UTIL_STLIB_FLAG(STLIB_BLOCK_INT)), \
115 _UTIL_STDLIB_DEF(STDLIB_SIGWAITINFO, "sigwaitinfo", _UTIL_STLIB_FLAG(STLIB_BLOCK_INT)), \
116 _UTIL_STDLIB_DEF(STDLIB_SLEEP, "sleep", _UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)), \
117 _UTIL_STDLIB_DEF(STDLIB_SOCKET, "socket", 0), \
118 _UTIL_STDLIB_DEF(STDLIB_USLEEP, "usleep", _UTIL_STLIB_FLAG(STLIB_BLOCK_EXT)), \
119 _UTIL_STDLIB_DEF(STDLIB_VALLOC, "valloc", 0), \
120 _UTIL_STDLIB_DEF(STDLIB_WAITPID, "waitpid", _UTIL_STLIB_FLAG(STLIB_BLOCK_INT)) \
123 static inline util_stdlib_t* util_stdlib_lookup_by_name(const char *name, util_stdlib_t *stlib_arr)
125 int i;
126 for (i=0;i<__NUM_STDLIBS_IDS;i++) {
127 if (!strcmp(name, stlib_arr[i].name)) {
128 return &stlib_arr[i];
132 return NULL;
135 static inline char* util_stdlib_flags_to_str(unsigned long flags,
136 char* buffer)
138 int i;
139 for(i=0;i<__NUM_STDLIBS_FLAGS;i++) {
140 buffer[i] = _UTIL_STLIB_FLAG_C(flags, i);
142 buffer[i] = '\0';
144 return buffer;
147 #endif /* _UTIL_STDLIB_H */