]> jfr.im git - solanum.git/blame - librb/include/rb_lib.h
librb: some win32 fixes
[solanum.git] / librb / include / rb_lib.h
CommitLineData
db137867
AC
1#ifndef RB_LIB_H
2#define RB_LIB_H 1
3
4#include <librb-config.h>
5#include <stdio.h>
6#include <limits.h>
7#include <stdarg.h>
8#include <assert.h>
9#include <fcntl.h>
10#include <signal.h>
11#include <ctype.h>
12
77cb59b3
AC
13#ifdef HAVE_LINUX_TCP_H
14# include <linux/tcp.h>
15#endif
16
db137867
AC
17#ifdef __GNUC__
18#undef alloca
19#define alloca __builtin_alloca
20#else
21# ifdef _MSC_VER
22# include <malloc.h>
23# define alloca _alloca
24# else
25# if RB_HAVE_ALLOCA_H
26# include <alloca.h>
27# else
28# ifdef _AIX
29#pragma alloca
30# else
31# ifndef alloca /* predefined by HP cc +Olibcalls */
32char *alloca();
33# endif
34# endif
35# endif
36# endif
37#endif /* __GNUC__ */
38
39#ifdef __GNUC__
40
c2ac22cc
VY
41#ifdef rb_likely
42#undef rb_likely
db137867 43#endif
c2ac22cc
VY
44#ifdef rb_unlikely
45#undef rb_unlikely
db137867
AC
46#endif
47
48#if __GNUC__ == 2 && __GNUC_MINOR__ < 96
49# define __builtin_expect(x, expected_value) (x)
50#endif
51
c2ac22cc
VY
52#define rb_likely(x) __builtin_expect(!!(x), 1)
53#define rb_unlikely(x) __builtin_expect(!!(x), 0)
db137867
AC
54
55#else /* !__GNUC__ */
56
57#define UNUSED(x) x
58
c2ac22cc
VY
59#ifdef rb_likely
60#undef rb_likely
db137867 61#endif
c2ac22cc
VY
62#ifdef rb_unlikely
63#undef rb_unlikely
db137867 64#endif
c2ac22cc
VY
65#define rb_likely(x) (x)
66#define rb_unlikely(x) (x)
db137867
AC
67#endif
68
69
70
3202e249 71#ifdef _WIN32
db137867
AC
72#include <process.h>
73
d74fa5b5
JT
74#ifndef PATH_MAX
75#define PATH_MAX 128
db137867
AC
76#endif
77
db137867
AC
78#ifdef strerror
79#undef strerror
80#endif
81
3202e249
VY
82#define strerror(x) rb_strerror(x)
83char *rb_strerror(int error);
db137867
AC
84
85
b68dee9b 86#ifndef ENOBUFS
db137867 87#define ENOBUFS WSAENOBUFS
b68dee9b
AC
88#endif
89
90#ifndef EINPROGRESS
db137867 91#define EINPROGRESS WSAEINPROGRESS
b68dee9b
AC
92#endif
93
94#ifndef EWOULDBLOCK
db137867 95#define EWOULDBLOCK WSAEWOULDBLOCK
b68dee9b
AC
96#endif
97
98#ifndef EMSGSIZE
db137867 99#define EMSGSIZE WSAEMSGSIZE
b68dee9b
AC
100#endif
101
102#ifndef EALREADY
db137867 103#define EALREADY WSAEALREADY
b68dee9b
AC
104#endif
105
106#ifndef EISCONN
db137867 107#define EISCONN WSAEISCONN
b68dee9b
AC
108#endif
109
110#ifndef EADDRINUSE
db137867 111#define EADDRINUSE WSAEADDRINUSE
b68dee9b
AC
112#endif
113
114#ifndef EAFNOSUPPORT
db137867 115#define EAFNOSUPPORT WSAEAFNOSUPPORT
b68dee9b 116#endif
db137867
AC
117
118#define pipe(x) _pipe(x, 1024, O_BINARY)
119#define ioctl(x,y,z) ioctlsocket(x,y, (u_long *)z)
120
db137867 121#define WNOHANG 1
db137867
AC
122
123#ifndef SIGKILL
124#define SIGKILL SIGTERM
125#endif
126
3202e249 127#endif /* _WIN32 */
db137867
AC
128
129
130
131#ifndef HOSTIPLEN
132#define HOSTIPLEN 53
133#endif
134
db137867 135#ifdef __GNUC__
3202e249 136#define slrb_assert(expr) do \
c2ac22cc
VY
137 if(rb_unlikely(!(expr))) { \
138 rb_lib_log( \
db137867
AC
139 "file: %s line: %d (%s): Assertion failed: (%s)", \
140 __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
db137867
AC
141 } \
142 while(0)
143#else
3202e249 144#define slrb_assert(expr) do \
c2ac22cc 145 if(rb_unlikely(!(expr))) { \
29c92cf9 146 rb_lib_log( \
db137867
AC
147 "file: %s line: %d: Assertion failed: (%s)", \
148 __FILE__, __LINE__, #expr); \
db137867
AC
149 } \
150 while(0)
151#endif
3202e249
VY
152
153#ifdef SOFT_ASSERT
154#define lrb_assert(expr) slrb_assert(expr)
db137867 155#else
3202e249 156#define lrb_assert(expr) do { slrb_assert(expr); assert(expr); } while(0)
db137867
AC
157#endif
158
9d9a4f60 159#ifdef RB_SOCKADDR_HAS_SA_LEN
db137867
AC
160#define ss_len sa_len
161#endif
162
3202e249
VY
163#define GET_SS_FAMILY(x) (((const struct sockaddr *)(x))->sa_family)
164#define SET_SS_FAMILY(x, y) ((((struct sockaddr *)(x))->sa_family) = y)
9d9a4f60 165#ifdef RB_SOCKADDR_HAS_SA_LEN
db137867
AC
166#define SET_SS_LEN(x, y) do { \
167 struct sockaddr *storage; \
168 storage = ((struct sockaddr *)(x));\
169 storage->sa_len = (y); \
170 } while (0)
171#define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_len)
9d9a4f60 172#else /* !RB_SOCKADDR_HAS_SA_LEN */
db137867
AC
173#define SET_SS_LEN(x, y) (((struct sockaddr *)(x))->sa_family = ((struct sockaddr *)(x))->sa_family)
174#ifdef RB_IPV6
175#define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
176#else
177#define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : 0)
178#endif
179#endif
180
181#ifndef INADDRSZ
182#define INADDRSZ 4
183#endif
184
185#ifndef IN6ADDRSZ
186#define IN6ADDRSZ 16
187#endif
188
189#ifndef INT16SZ
190#define INT16SZ 2
191#endif
192
41aed6bb
SA
193#ifndef UINT16_MAX
194#define UINT16_MAX (65535U)
195#endif
196
db137867
AC
197
198typedef void log_cb(const char *buffer);
199typedef void restart_cb(const char *buffer);
200typedef void die_cb(const char *buffer);
201
202char *rb_ctime(const time_t, char *, size_t);
203char *rb_date(const time_t, char *, size_t);
204void rb_lib_log(const char *, ...);
205void rb_lib_restart(const char *, ...);
206void rb_lib_die(const char *, ...);
207void rb_set_time(void);
208const char *rb_lib_version(void);
209
210void rb_lib_init(log_cb * xilog, restart_cb * irestart, die_cb * idie, int closeall, int maxfds,
211 size_t dh_size, size_t fd_heap_size);
212void rb_lib_loop(long delay);
213
214time_t rb_current_time(void);
215const struct timeval *rb_current_time_tv(void);
216pid_t rb_spawn_process(const char *, const char **);
217
218char *rb_strtok_r(char *, const char *, char **);
219
220int rb_gettimeofday(struct timeval *, void *);
221
222void rb_sleep(unsigned int seconds, unsigned int useconds);
223char *rb_crypt(const char *, const char *);
224
225unsigned char *rb_base64_encode(const unsigned char *str, int length);
226unsigned char *rb_base64_decode(const unsigned char *str, int length, int *ret);
3202e249
VY
227int rb_kill(pid_t, int);
228char *rb_strerror(int);
db137867 229
3202e249 230int rb_setenv(const char *, const char *, int);
db137867 231
3202e249
VY
232pid_t rb_waitpid(pid_t pid, int *status, int options);
233pid_t rb_getpid(void);
234//unsigned int rb_geteuid(void);
db137867 235
030272f3 236
db137867
AC
237#include <rb_tools.h>
238#include <rb_memory.h>
239#include <rb_commio.h>
240#include <rb_balloc.h>
241#include <rb_linebuf.h>
db137867
AC
242#include <rb_event.h>
243#include <rb_helper.h>
244#include <rb_rawbuf.h>
245#include <rb_patricia.h>
246
247#endif