]>
Commit | Line | Data |
---|---|---|
b57f37fb | 1 | /* |
f030cae8 | 2 | * $Id: ratbox_lib.h 26256 2008-12-10 04:05:26Z androsyn $ |
b57f37fb WP |
3 | */ |
4 | ||
5 | #ifndef RB_LIB_H | |
6 | #define RB_LIB_H 1 | |
7 | ||
8 | #include <librb-config.h> | |
9 | #include <stdio.h> | |
10 | #include <limits.h> | |
11 | #include <stdarg.h> | |
12 | #include <assert.h> | |
13 | #include <fcntl.h> | |
14 | #include <signal.h> | |
15 | #include <ctype.h> | |
16 | ||
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 */ | |
32 | char *alloca(); | |
33 | # endif | |
34 | # endif | |
35 | # endif | |
36 | # endif | |
37 | #endif /* __GNUC__ */ | |
38 | ||
39 | #ifdef __GNUC__ | |
40 | ||
033be687 VY |
41 | #ifdef rb_likely |
42 | #undef rb_likely | |
b57f37fb | 43 | #endif |
033be687 VY |
44 | #ifdef rb_unlikely |
45 | #undef rb_unlikely | |
b57f37fb WP |
46 | #endif |
47 | ||
48 | #if __GNUC__ == 2 && __GNUC_MINOR__ < 96 | |
49 | # define __builtin_expect(x, expected_value) (x) | |
50 | #endif | |
51 | ||
033be687 VY |
52 | #define rb_likely(x) __builtin_expect(!!(x), 1) |
53 | #define rb_unlikely(x) __builtin_expect(!!(x), 0) | |
b57f37fb WP |
54 | |
55 | #else /* !__GNUC__ */ | |
56 | ||
57 | #define UNUSED(x) x | |
58 | ||
033be687 VY |
59 | #ifdef rb_likely |
60 | #undef rb_likely | |
b57f37fb | 61 | #endif |
033be687 VY |
62 | #ifdef rb_unlikely |
63 | #undef rb_unlikely | |
b57f37fb | 64 | #endif |
033be687 VY |
65 | #define rb_likely(x) (x) |
66 | #define rb_unlikely(x) (x) | |
b57f37fb WP |
67 | #endif |
68 | ||
69 | ||
70 | ||
94b4fbf9 | 71 | #ifdef _WIN32 |
b57f37fb WP |
72 | #include <process.h> |
73 | ||
74 | #ifndef MAXPATHLEN | |
75 | #define MAXPATHLEN 128 | |
76 | #endif | |
77 | ||
b57f37fb WP |
78 | #ifdef strerror |
79 | #undef strerror | |
80 | #endif | |
81 | ||
94b4fbf9 VY |
82 | #define strerror(x) rb_strerror(x) |
83 | char *rb_strerror(int error); | |
b57f37fb WP |
84 | |
85 | ||
86 | #define ENOBUFS WSAENOBUFS | |
87 | #define EINPROGRESS WSAEINPROGRESS | |
88 | #define EWOULDBLOCK WSAEWOULDBLOCK | |
89 | #define EMSGSIZE WSAEMSGSIZE | |
90 | #define EALREADY WSAEALREADY | |
91 | #define EISCONN WSAEISCONN | |
92 | #define EADDRINUSE WSAEADDRINUSE | |
93 | #define EAFNOSUPPORT WSAEAFNOSUPPORT | |
94 | ||
95 | #define pipe(x) _pipe(x, 1024, O_BINARY) | |
96 | #define ioctl(x,y,z) ioctlsocket(x,y, (u_long *)z) | |
97 | ||
b57f37fb | 98 | #define WNOHANG 1 |
b57f37fb WP |
99 | |
100 | #ifndef SIGKILL | |
101 | #define SIGKILL SIGTERM | |
102 | #endif | |
103 | ||
94b4fbf9 | 104 | #endif /* _WIN32 */ |
b57f37fb WP |
105 | |
106 | ||
107 | ||
108 | #ifndef HOSTIPLEN | |
109 | #define HOSTIPLEN 53 | |
110 | #endif | |
111 | ||
b57f37fb | 112 | #ifdef __GNUC__ |
94b4fbf9 | 113 | #define slrb_assert(expr) do \ |
033be687 VY |
114 | if(rb_unlikely(!(expr))) { \ |
115 | rb_lib_log( \ | |
b57f37fb WP |
116 | "file: %s line: %d (%s): Assertion failed: (%s)", \ |
117 | __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \ | |
b57f37fb WP |
118 | } \ |
119 | while(0) | |
120 | #else | |
94b4fbf9 | 121 | #define slrb_assert(expr) do \ |
033be687 VY |
122 | if(rb_unlikely(!(expr))) { \ |
123 | rb_lib_log(L_MAIN, \ | |
b57f37fb WP |
124 | "file: %s line: %d: Assertion failed: (%s)", \ |
125 | __FILE__, __LINE__, #expr); \ | |
b57f37fb WP |
126 | } \ |
127 | while(0) | |
128 | #endif | |
94b4fbf9 VY |
129 | |
130 | #ifdef SOFT_ASSERT | |
131 | #define lrb_assert(expr) slrb_assert(expr) | |
b57f37fb | 132 | #else |
94b4fbf9 | 133 | #define lrb_assert(expr) do { slrb_assert(expr); assert(expr); } while(0) |
b57f37fb WP |
134 | #endif |
135 | ||
b5d9e56c | 136 | #ifdef RB_SOCKADDR_HAS_SA_LEN |
b57f37fb WP |
137 | #define ss_len sa_len |
138 | #endif | |
139 | ||
94b4fbf9 VY |
140 | #define GET_SS_FAMILY(x) (((const struct sockaddr *)(x))->sa_family) |
141 | #define SET_SS_FAMILY(x, y) ((((struct sockaddr *)(x))->sa_family) = y) | |
b5d9e56c | 142 | #ifdef RB_SOCKADDR_HAS_SA_LEN |
b57f37fb WP |
143 | #define SET_SS_LEN(x, y) do { \ |
144 | struct sockaddr *storage; \ | |
145 | storage = ((struct sockaddr *)(x));\ | |
146 | storage->sa_len = (y); \ | |
147 | } while (0) | |
148 | #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_len) | |
b5d9e56c | 149 | #else /* !RB_SOCKADDR_HAS_SA_LEN */ |
b57f37fb WP |
150 | #define SET_SS_LEN(x, y) (((struct sockaddr *)(x))->sa_family = ((struct sockaddr *)(x))->sa_family) |
151 | #ifdef RB_IPV6 | |
152 | #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)) | |
153 | #else | |
154 | #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : 0) | |
155 | #endif | |
156 | #endif | |
157 | ||
158 | #ifndef INADDRSZ | |
159 | #define INADDRSZ 4 | |
160 | #endif | |
161 | ||
162 | #ifndef IN6ADDRSZ | |
163 | #define IN6ADDRSZ 16 | |
164 | #endif | |
165 | ||
166 | #ifndef INT16SZ | |
167 | #define INT16SZ 2 | |
168 | #endif | |
169 | ||
170 | ||
171 | typedef void log_cb(const char *buffer); | |
172 | typedef void restart_cb(const char *buffer); | |
173 | typedef void die_cb(const char *buffer); | |
174 | ||
175 | char *rb_ctime(const time_t, char *, size_t); | |
176 | char *rb_date(const time_t, char *, size_t); | |
177 | void rb_lib_log(const char *, ...); | |
178 | void rb_lib_restart(const char *, ...); | |
179 | void rb_lib_die(const char *, ...); | |
180 | void rb_set_time(void); | |
181 | const char *rb_lib_version(void); | |
182 | ||
183 | void rb_lib_init(log_cb * xilog, restart_cb * irestart, die_cb * idie, int closeall, int maxfds, | |
184 | size_t dh_size, size_t fd_heap_size); | |
185 | void rb_lib_loop(long delay); | |
186 | ||
187 | time_t rb_current_time(void); | |
188 | const struct timeval *rb_current_time_tv(void); | |
189 | pid_t rb_spawn_process(const char *, const char **); | |
190 | ||
191 | char *rb_strtok_r(char *, const char *, char **); | |
192 | ||
193 | int rb_gettimeofday(struct timeval *, void *); | |
194 | ||
195 | void rb_sleep(unsigned int seconds, unsigned int useconds); | |
196 | char *rb_crypt(const char *, const char *); | |
197 | ||
198 | unsigned char *rb_base64_encode(const unsigned char *str, int length); | |
199 | unsigned char *rb_base64_decode(const unsigned char *str, int length, int *ret); | |
94b4fbf9 VY |
200 | int rb_kill(pid_t, int); |
201 | char *rb_strerror(int); | |
b57f37fb | 202 | |
94b4fbf9 | 203 | int rb_setenv(const char *, const char *, int); |
b57f37fb | 204 | |
94b4fbf9 VY |
205 | pid_t rb_waitpid(pid_t pid, int *status, int options); |
206 | pid_t rb_getpid(void); | |
207 | //unsigned int rb_geteuid(void); | |
b57f37fb | 208 | |
f030cae8 | 209 | |
b57f37fb WP |
210 | #include <rb_tools.h> |
211 | #include <rb_memory.h> | |
212 | #include <rb_commio.h> | |
213 | #include <rb_balloc.h> | |
214 | #include <rb_linebuf.h> | |
215 | #include <rb_snprintf.h> | |
216 | #include <rb_event.h> | |
217 | #include <rb_helper.h> | |
218 | #include <rb_rawbuf.h> | |
219 | #include <rb_patricia.h> | |
220 | ||
221 | #endif |