]>
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 /* For those unfamiliar with GNU format attributes, a is the 1 based
132 * argument number of the format string, and b is the 1 based argument
133 * number of the variadic ... */
135 #define AFP(a,b) __attribute__((format (printf, a, b)))
142 #define slrb_assert(expr) ( \
143 rb_likely((expr)) || ( \
145 "file: %s line: %d (%s): Assertion failed: (%s)", \
146 __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr), 0) \
149 #define slrb_assert(expr) ( \
150 rb_likely((expr)) || ( \
152 "file: %s line: %d: Assertion failed: (%s)", \
153 __FILE__, __LINE__, #expr), 0) \
157 /* evaluates to true if assertion fails */
159 #define lrb_assert(expr) (!slrb_assert(expr))
161 #define lrb_assert(expr) (assert(slrb_assert(expr)), 0)
164 #ifdef RB_SOCKADDR_HAS_SA_LEN
165 #define ss_len sa_len
168 #define GET_SS_FAMILY(x) (((const struct sockaddr *)(x))->sa_family)
169 #define SET_SS_FAMILY(x, y) ((((struct sockaddr *)(x))->sa_family) = y)
170 #ifdef RB_SOCKADDR_HAS_SA_LEN
171 #define SET_SS_LEN(x, y) do { \
172 struct sockaddr *_storage; \
173 _storage = ((struct sockaddr *)(x));\
174 _storage->sa_len = (y); \
176 #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_len)
177 #else /* !RB_SOCKADDR_HAS_SA_LEN */
178 #define SET_SS_LEN(x, y) (((struct sockaddr *)(x))->sa_family = ((struct sockaddr *)(x))->sa_family)
179 #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
182 #define GET_SS_PORT(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? ((struct sockaddr_in *)(x))->sin_port : ((struct sockaddr_in6 *)(x))->sin6_port)
183 #define SET_SS_PORT(x, y) do { \
184 if(((struct sockaddr *)(x))->sa_family == AF_INET) { \
185 ((struct sockaddr_in *)(x))->sin_port = (y); \
187 ((struct sockaddr_in6 *)(x))->sin6_port = (y); \
204 #define UINT16_MAX (65535U)
208 #define UINT32_MAX (4294967295U)
212 typedef void log_cb(const char *buffer
);
213 typedef void restart_cb(const char *buffer
);
214 typedef void die_cb(const char *buffer
);
216 char *rb_ctime(const time_t, char *, size_t);
217 char *rb_date(const time_t, char *, size_t);
218 void rb_lib_log(const char *, ...);
219 void rb_lib_restart(const char *, ...) __attribute__((noreturn
));
220 void rb_lib_die(const char *, ...);
221 void rb_set_time(void);
222 const char *rb_lib_version(void);
224 void rb_lib_init(log_cb
* xilog
, restart_cb
* irestart
, die_cb
* idie
, int closeall
, int maxfds
,
225 size_t dh_size
, size_t fd_heap_size
);
226 void rb_lib_loop(long delay
) __attribute__((noreturn
));
228 time_t rb_current_time(void);
229 const struct timeval
*rb_current_time_tv(void);
230 pid_t
rb_spawn_process(const char *, const char **);
232 char *rb_strtok_r(char *, const char *, char **);
234 int rb_gettimeofday(struct timeval
*, void *);
236 void rb_sleep(unsigned int seconds
, unsigned int useconds
);
237 char *rb_crypt(const char *, const char *);
239 unsigned char *rb_base64_encode(const unsigned char *str
, int length
);
240 unsigned char *rb_base64_decode(const unsigned char *str
, int length
, int *ret
);
241 int rb_kill(pid_t
, int);
242 char *rb_strerror(int);
244 int rb_setenv(const char *, const char *, int);
246 pid_t
rb_waitpid(pid_t pid
, int *status
, int options
);
247 pid_t
rb_getpid(void);
248 //unsigned int rb_geteuid(void);
251 #include <rb_tools.h>
252 #include <rb_memory.h>
253 #include <rb_commio.h>
254 #include <rb_balloc.h>
255 #include <rb_linebuf.h>
256 #include <rb_event.h>
257 #include <rb_helper.h>
258 #include <rb_rawbuf.h>
259 #include <rb_patricia.h>