]>
Commit | Line | Data |
---|---|---|
db137867 | 1 | /* |
c2ac22cc | 2 | * $Id: ratbox_lib.h 25375 2008-05-16 15:19:51Z androsyn $ |
db137867 AC |
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 | ||
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 | ||
71 | #ifdef WIN32 | |
72 | #include <process.h> | |
73 | ||
74 | #ifndef MAXPATHLEN | |
75 | #define MAXPATHLEN 128 | |
76 | #endif | |
77 | ||
78 | ||
79 | #ifdef strerror | |
80 | #undef strerror | |
81 | #endif | |
82 | ||
83 | #define strerror(x) wsock_strerror(x) | |
84 | const char *wsock_strerror(int error); | |
85 | ||
86 | ||
87 | #define ENOBUFS WSAENOBUFS | |
88 | #define EINPROGRESS WSAEINPROGRESS | |
89 | #define EWOULDBLOCK WSAEWOULDBLOCK | |
90 | #define EMSGSIZE WSAEMSGSIZE | |
91 | #define EALREADY WSAEALREADY | |
92 | #define EISCONN WSAEISCONN | |
93 | #define EADDRINUSE WSAEADDRINUSE | |
94 | #define EAFNOSUPPORT WSAEAFNOSUPPORT | |
95 | ||
96 | #define pipe(x) _pipe(x, 1024, O_BINARY) | |
97 | #define ioctl(x,y,z) ioctlsocket(x,y, (u_long *)z) | |
98 | ||
99 | int setenv(const char *, const char *, int); | |
100 | int kill(int pid, int sig); | |
101 | #define WNOHANG 1 | |
102 | pid_t waitpid(pid_t pid, int *status, int options); | |
103 | pid_t getpid(void); | |
104 | unsigned int geteuid(void); | |
105 | ||
106 | #ifndef SIGKILL | |
107 | #define SIGKILL SIGTERM | |
108 | #endif | |
109 | ||
110 | #endif /* WIN32 */ | |
111 | ||
112 | ||
113 | ||
114 | #ifndef HOSTIPLEN | |
115 | #define HOSTIPLEN 53 | |
116 | #endif | |
117 | ||
118 | #ifdef SOFT_ASSERT | |
119 | #ifdef __GNUC__ | |
120 | #define lrb_assert(expr) do \ | |
c2ac22cc VY |
121 | if(rb_unlikely(!(expr))) { \ |
122 | rb_lib_log( \ | |
db137867 AC |
123 | "file: %s line: %d (%s): Assertion failed: (%s)", \ |
124 | __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \ | |
db137867 AC |
125 | } \ |
126 | while(0) | |
127 | #else | |
128 | #define lrb_assert(expr) do \ | |
c2ac22cc VY |
129 | if(rb_unlikely(!(expr))) { \ |
130 | rb_lib_log(L_MAIN, \ | |
db137867 AC |
131 | "file: %s line: %d: Assertion failed: (%s)", \ |
132 | __FILE__, __LINE__, #expr); \ | |
db137867 AC |
133 | } \ |
134 | while(0) | |
135 | #endif | |
136 | #else | |
137 | #define lrb_assert(expr) assert(expr) | |
138 | #endif | |
139 | ||
9d9a4f60 | 140 | #ifdef RB_SOCKADDR_HAS_SA_LEN |
db137867 AC |
141 | #define ss_len sa_len |
142 | #endif | |
143 | ||
144 | #define GET_SS_FAMILY(x) (((struct sockaddr *)(x))->sa_family) | |
145 | ||
9d9a4f60 | 146 | #ifdef RB_SOCKADDR_HAS_SA_LEN |
db137867 AC |
147 | #define SET_SS_LEN(x, y) do { \ |
148 | struct sockaddr *storage; \ | |
149 | storage = ((struct sockaddr *)(x));\ | |
150 | storage->sa_len = (y); \ | |
151 | } while (0) | |
152 | #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_len) | |
9d9a4f60 | 153 | #else /* !RB_SOCKADDR_HAS_SA_LEN */ |
db137867 AC |
154 | #define SET_SS_LEN(x, y) (((struct sockaddr *)(x))->sa_family = ((struct sockaddr *)(x))->sa_family) |
155 | #ifdef RB_IPV6 | |
156 | #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)) | |
157 | #else | |
158 | #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : 0) | |
159 | #endif | |
160 | #endif | |
161 | ||
162 | #ifndef INADDRSZ | |
163 | #define INADDRSZ 4 | |
164 | #endif | |
165 | ||
166 | #ifndef IN6ADDRSZ | |
167 | #define IN6ADDRSZ 16 | |
168 | #endif | |
169 | ||
170 | #ifndef INT16SZ | |
171 | #define INT16SZ 2 | |
172 | #endif | |
173 | ||
174 | ||
175 | typedef void log_cb(const char *buffer); | |
176 | typedef void restart_cb(const char *buffer); | |
177 | typedef void die_cb(const char *buffer); | |
178 | ||
179 | char *rb_ctime(const time_t, char *, size_t); | |
180 | char *rb_date(const time_t, char *, size_t); | |
181 | void rb_lib_log(const char *, ...); | |
182 | void rb_lib_restart(const char *, ...); | |
183 | void rb_lib_die(const char *, ...); | |
184 | void rb_set_time(void); | |
185 | const char *rb_lib_version(void); | |
186 | ||
187 | void rb_lib_init(log_cb * xilog, restart_cb * irestart, die_cb * idie, int closeall, int maxfds, | |
188 | size_t dh_size, size_t fd_heap_size); | |
189 | void rb_lib_loop(long delay); | |
190 | ||
191 | time_t rb_current_time(void); | |
192 | const struct timeval *rb_current_time_tv(void); | |
193 | pid_t rb_spawn_process(const char *, const char **); | |
194 | ||
195 | char *rb_strtok_r(char *, const char *, char **); | |
196 | ||
197 | int rb_gettimeofday(struct timeval *, void *); | |
198 | ||
199 | void rb_sleep(unsigned int seconds, unsigned int useconds); | |
200 | char *rb_crypt(const char *, const char *); | |
201 | ||
202 | unsigned char *rb_base64_encode(const unsigned char *str, int length); | |
203 | unsigned char *rb_base64_decode(const unsigned char *str, int length, int *ret); | |
204 | ||
205 | ||
206 | ||
207 | #include <rb_tools.h> | |
208 | #include <rb_memory.h> | |
209 | #include <rb_commio.h> | |
210 | #include <rb_balloc.h> | |
211 | #include <rb_linebuf.h> | |
212 | #include <rb_snprintf.h> | |
213 | #include <rb_event.h> | |
214 | #include <rb_helper.h> | |
215 | #include <rb_rawbuf.h> | |
216 | #include <rb_patricia.h> | |
217 | ||
218 | #endif |