]>
jfr.im git - solanum.git/blob - librb/include/rb_lib.h
4 #include <librb-config.h>
15 #define alloca __builtin_alloca
19 # define alloca _alloca
27 # ifndef alloca /* predefined by HP cc +Olibcalls */
44 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
45 # define __builtin_expect(x, expected_value) (x)
48 #define rb_likely(x) __builtin_expect(!!(x), 1)
49 #define rb_unlikely(x) __builtin_expect(!!(x), 0)
61 #define rb_likely(x) (x)
62 #define rb_unlikely(x) (x)
66 #define rb_get_errno() do { errno = WSAGetLastError(); WSASetLastError(errno); } while(0)
67 typedef SOCKET rb_platform_fd_t
;
68 #define RB_PATH_SEPARATOR '\\'
70 #define rb_get_errno()
71 typedef int rb_platform_fd_t
;
72 #define RB_PATH_SEPARATOR '/'
86 #define strerror(x) rb_strerror(x)
87 char *rb_strerror(int error
);
90 #define ENOBUFS WSAENOBUFS
93 #define EINPROGRESS WSAEINPROGRESS
96 #define EWOULDBLOCK WSAEWOULDBLOCK
99 #define EMSGSIZE WSAEMSGSIZE
102 #define EALREADY WSAEALREADY
105 #define EISCONN WSAEISCONN
108 #define EADDRINUSE WSAEADDRINUSE
111 #define EAFNOSUPPORT WSAEAFNOSUPPORT
113 #define pipe(x) _pipe(x, 1024, O_BINARY)
114 #define ioctl(x,y,z) ioctlsocket(x,y, (unsigned long *)z)
119 #define SIGKILL SIGTERM
131 #define slrb_assert(expr) do \
132 if(rb_unlikely(!(expr))) { \
134 "file: %s line: %d (%s): Assertion failed: (%s)", \
135 __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
139 #define slrb_assert(expr) do \
140 if(rb_unlikely(!(expr))) { \
142 "file: %s line: %d: Assertion failed: (%s)", \
143 __FILE__, __LINE__, #expr); \
149 #define lrb_assert(expr) slrb_assert(expr)
151 #define lrb_assert(expr) do { slrb_assert(expr); assert(expr); } while(0)
154 #ifdef RB_SOCKADDR_HAS_SA_LEN
155 #define ss_len sa_len
158 #define GET_SS_FAMILY(x) (((const struct sockaddr *)(x))->sa_family)
159 #define SET_SS_FAMILY(x, y) ((((struct sockaddr *)(x))->sa_family) = y)
160 #ifdef RB_SOCKADDR_HAS_SA_LEN
161 #define SET_SS_LEN(x, y) do { \
162 struct sockaddr *_storage; \
163 _storage = ((struct sockaddr *)(x));\
164 _storage->sa_len = (y); \
166 #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_len)
167 #else /* !RB_SOCKADDR_HAS_SA_LEN */
168 #define SET_SS_LEN(x, y) (((struct sockaddr *)(x))->sa_family = ((struct sockaddr *)(x))->sa_family)
170 #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
172 #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : 0)
177 #define GET_SS_PORT(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? ((struct sockaddr_in *)(x))->sin_port : ((struct sockaddr_in6 *)(x))->sin6_port)
178 #define SET_SS_PORT(x, y) do { \
179 if(((struct sockaddr *)(x))->sa_family == AF_INET) { \
180 ((struct sockaddr_in *)(x))->sin_port = (y); \
182 ((struct sockaddr_in6 *)(x))->sin6_port = (y); \
186 #define GET_SS_PORT(x) (((struct sockaddr_in *)(x))->sin_port)
187 #define SET_SS_PORT(x, y) (((struct sockaddr_in *)(x))->sin_port = y)
203 #define UINT16_MAX (65535U)
207 #define UINT32_MAX (4294967295U)
211 typedef void log_cb(const char *buffer
);
212 typedef void restart_cb(const char *buffer
);
213 typedef void die_cb(const char *buffer
);
215 char *rb_ctime(const time_t, char *, size_t);
216 char *rb_date(const time_t, char *, size_t);
217 void rb_lib_log(const char *, ...);
218 void rb_lib_restart(const char *, ...) __attribute__((noreturn
));
219 void rb_lib_die(const char *, ...);
220 void rb_set_time(void);
221 const char *rb_lib_version(void);
223 void rb_lib_init(log_cb
* xilog
, restart_cb
* irestart
, die_cb
* idie
, int closeall
, int maxfds
,
224 size_t dh_size
, size_t fd_heap_size
);
225 void rb_lib_loop(long delay
) __attribute__((noreturn
));
227 time_t rb_current_time(void);
228 const struct timeval
*rb_current_time_tv(void);
229 pid_t
rb_spawn_process(const char *, const char **);
231 char *rb_strtok_r(char *, const char *, char **);
233 int rb_gettimeofday(struct timeval
*, void *);
235 void rb_sleep(unsigned int seconds
, unsigned int useconds
);
236 char *rb_crypt(const char *, const char *);
238 unsigned char *rb_base64_encode(const unsigned char *str
, int length
);
239 unsigned char *rb_base64_decode(const unsigned char *str
, int length
, int *ret
);
240 int rb_kill(pid_t
, int);
241 char *rb_strerror(int);
243 int rb_setenv(const char *, const char *, int);
245 pid_t
rb_waitpid(pid_t pid
, int *status
, int options
);
246 pid_t
rb_getpid(void);
247 //unsigned int rb_geteuid(void);
250 #include <rb_tools.h>
251 #include <rb_memory.h>
252 #include <rb_commio.h>
253 #include <rb_balloc.h>
254 #include <rb_linebuf.h>
255 #include <rb_event.h>
256 #include <rb_helper.h>
257 #include <rb_rawbuf.h>
258 #include <rb_patricia.h>