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