]> jfr.im git - irc/rqf/shadowircd.git/blame - libratbox/include/ratbox_lib.h
dlink -> rb_dlink
[irc/rqf/shadowircd.git] / libratbox / include / ratbox_lib.h
CommitLineData
b57f37fb
WP
1/*
2 * $Id: ratbox_lib.h 24866 2008-01-10 16:33:54Z androsyn $
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 */
32char *alloca();
33# endif
34# endif
35# endif
36# endif
37#endif /* __GNUC__ */
38
39#ifdef __GNUC__
40
41#ifdef likely
42#undef likely
43#endif
44#ifdef unlikely
45#undef unlikely
46#endif
47
48#if __GNUC__ == 2 && __GNUC_MINOR__ < 96
49# define __builtin_expect(x, expected_value) (x)
50#endif
51
52#define likely(x) __builtin_expect(!!(x), 1)
53#define unlikely(x) __builtin_expect(!!(x), 0)
54
55#else /* !__GNUC__ */
56
57#define UNUSED(x) x
58
59#ifdef likely
60#undef likely
61#endif
62#ifdef unlikely
63#undef unlikely
64#endif
65#define likely(x) (x)
66#define unlikely(x) (x)
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)
84const 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
99int setenv(const char *, const char *, int);
100int kill(int pid, int sig);
101#define WNOHANG 1
102pid_t waitpid(pid_t pid, int *status, int options);
103pid_t getpid(void);
104unsigned 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 \
121 if(unlikely(!(expr))) { \
122 lib_ilog(L_MAIN, \
123 "file: %s line: %d (%s): Assertion failed: (%s)", \
124 __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
125 sendto_realops_flags(UMODE_ALL, L_ALL, \
126 "file: %s line: %d (%s): Assertion failed: (%s)", \
127 __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
128 } \
129 while(0)
130#else
131#define lrb_assert(expr) do \
132 if(unlikely(!(expr))) { \
133 lib_ilog(L_MAIN, \
134 "file: %s line: %d: Assertion failed: (%s)", \
135 __FILE__, __LINE__, #expr); \
136 sendto_realops_flags(UMODE_ALL, L_ALL, \
137 "file: %s line: %d: Assertion failed: (%s)" \
138 __FILE__, __LINE__, #expr); \
139 } \
140 while(0)
141#endif
142#else
143#define lrb_assert(expr) assert(expr)
144#endif
145
146#ifdef SOCKADDR_IN_HAS_LEN
147#define ss_len sa_len
148#endif
149
150#define GET_SS_FAMILY(x) (((struct sockaddr *)(x))->sa_family)
151
152#ifdef SOCKADDR_IN_HAS_LEN
153#define SET_SS_LEN(x, y) do { \
154 struct sockaddr *storage; \
155 storage = ((struct sockaddr *)(x));\
156 storage->sa_len = (y); \
157 } while (0)
158#define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_len)
159#else /* !SOCKADDR_IN_HAS_LEN */
160#define SET_SS_LEN(x, y) (((struct sockaddr *)(x))->sa_family = ((struct sockaddr *)(x))->sa_family)
161#ifdef RB_IPV6
162#define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
163#else
164#define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : 0)
165#endif
166#endif
167
168#ifndef INADDRSZ
169#define INADDRSZ 4
170#endif
171
172#ifndef IN6ADDRSZ
173#define IN6ADDRSZ 16
174#endif
175
176#ifndef INT16SZ
177#define INT16SZ 2
178#endif
179
180
181typedef void log_cb(const char *buffer);
182typedef void restart_cb(const char *buffer);
183typedef void die_cb(const char *buffer);
184
185char *rb_ctime(const time_t, char *, size_t);
186char *rb_date(const time_t, char *, size_t);
187void rb_lib_log(const char *, ...);
188void rb_lib_restart(const char *, ...);
189void rb_lib_die(const char *, ...);
190void rb_set_time(void);
191const char *rb_lib_version(void);
192
193void rb_lib_init(log_cb * xilog, restart_cb * irestart, die_cb * idie, int closeall, int maxfds,
194 size_t dh_size, size_t fd_heap_size);
195void rb_lib_loop(long delay);
196
197time_t rb_current_time(void);
198const struct timeval *rb_current_time_tv(void);
199pid_t rb_spawn_process(const char *, const char **);
200
201char *rb_strtok_r(char *, const char *, char **);
202
203int rb_gettimeofday(struct timeval *, void *);
204
205void rb_sleep(unsigned int seconds, unsigned int useconds);
206char *rb_crypt(const char *, const char *);
207
208unsigned char *rb_base64_encode(const unsigned char *str, int length);
209unsigned char *rb_base64_decode(const unsigned char *str, int length, int *ret);
210
211
212
213#include <rb_tools.h>
214#include <rb_memory.h>
215#include <rb_commio.h>
216#include <rb_balloc.h>
217#include <rb_linebuf.h>
218#include <rb_snprintf.h>
219#include <rb_event.h>
220#include <rb_helper.h>
221#include <rb_rawbuf.h>
222#include <rb_patricia.h>
223
224#endif