8 typedef struct util_stdlib_s
{
14 typedef enum util_stdlib_id_e
{
33 STDLIB_POSIX_MEMALIGN
,
35 STDLIB_PTHREAD_COND_WAIT
,
36 STDLIB_PTHREAD_COND_TIMEDWAIT
,
61 typedef enum util_stdlib_flag_e
{
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
)
126 for (i
=0;i
<__NUM_STDLIBS_IDS
;i
++) {
127 if (!strcmp(name
, stlib_arr
[i
].name
)) {
128 return &stlib_arr
[i
];
135 static inline char* util_stdlib_flags_to_str(unsigned long flags
,
139 for(i
=0;i
<__NUM_STDLIBS_FLAGS
;i
++) {
140 buffer
[i
] = _UTIL_STLIB_FLAG_C(flags
, i
);
147 #endif /* _UTIL_STDLIB_H */