]> jfr.im git - solanum.git/blame - libratbox/include/ratbox_lib.h
Spring cleaning redux:
[solanum.git] / libratbox / include / ratbox_lib.h
CommitLineData
db137867 1/*
030272f3 2 * $Id: ratbox_lib.h 26256 2008-12-10 04:05:26Z 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
77cb59b3
AC
17#ifdef HAVE_LINUX_TCP_H
18# include <linux/tcp.h>
19#endif
20
db137867
AC
21#ifdef __GNUC__
22#undef alloca
23#define alloca __builtin_alloca
24#else
25# ifdef _MSC_VER
26# include <malloc.h>
27# define alloca _alloca
28# else
29# if RB_HAVE_ALLOCA_H
30# include <alloca.h>
31# else
32# ifdef _AIX
33#pragma alloca
34# else
35# ifndef alloca /* predefined by HP cc +Olibcalls */
36char *alloca();
37# endif
38# endif
39# endif
40# endif
41#endif /* __GNUC__ */
42
43#ifdef __GNUC__
44
c2ac22cc
VY
45#ifdef rb_likely
46#undef rb_likely
db137867 47#endif
c2ac22cc
VY
48#ifdef rb_unlikely
49#undef rb_unlikely
db137867
AC
50#endif
51
52#if __GNUC__ == 2 && __GNUC_MINOR__ < 96
53# define __builtin_expect(x, expected_value) (x)
54#endif
55
c2ac22cc
VY
56#define rb_likely(x) __builtin_expect(!!(x), 1)
57#define rb_unlikely(x) __builtin_expect(!!(x), 0)
db137867
AC
58
59#else /* !__GNUC__ */
60
61#define UNUSED(x) x
62
c2ac22cc
VY
63#ifdef rb_likely
64#undef rb_likely
db137867 65#endif
c2ac22cc
VY
66#ifdef rb_unlikely
67#undef rb_unlikely
db137867 68#endif
c2ac22cc
VY
69#define rb_likely(x) (x)
70#define rb_unlikely(x) (x)
db137867
AC
71#endif
72
73
74
3202e249 75#ifdef _WIN32
db137867
AC
76#include <process.h>
77
d74fa5b5
JT
78#ifndef PATH_MAX
79#define PATH_MAX 128
db137867
AC
80#endif
81
db137867
AC
82#ifdef strerror
83#undef strerror
84#endif
85
3202e249
VY
86#define strerror(x) rb_strerror(x)
87char *rb_strerror(int error);
db137867
AC
88
89
90#define ENOBUFS WSAENOBUFS
91#define EINPROGRESS WSAEINPROGRESS
92#define EWOULDBLOCK WSAEWOULDBLOCK
93#define EMSGSIZE WSAEMSGSIZE
94#define EALREADY WSAEALREADY
95#define EISCONN WSAEISCONN
96#define EADDRINUSE WSAEADDRINUSE
97#define EAFNOSUPPORT WSAEAFNOSUPPORT
98
99#define pipe(x) _pipe(x, 1024, O_BINARY)
100#define ioctl(x,y,z) ioctlsocket(x,y, (u_long *)z)
101
db137867 102#define WNOHANG 1
db137867
AC
103
104#ifndef SIGKILL
105#define SIGKILL SIGTERM
106#endif
107
3202e249 108#endif /* _WIN32 */
db137867
AC
109
110
111
112#ifndef HOSTIPLEN
113#define HOSTIPLEN 53
114#endif
115
db137867 116#ifdef __GNUC__
3202e249 117#define slrb_assert(expr) do \
c2ac22cc
VY
118 if(rb_unlikely(!(expr))) { \
119 rb_lib_log( \
db137867
AC
120 "file: %s line: %d (%s): Assertion failed: (%s)", \
121 __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
db137867
AC
122 } \
123 while(0)
124#else
3202e249 125#define slrb_assert(expr) do \
c2ac22cc 126 if(rb_unlikely(!(expr))) { \
29c92cf9 127 rb_lib_log( \
db137867
AC
128 "file: %s line: %d: Assertion failed: (%s)", \
129 __FILE__, __LINE__, #expr); \
db137867
AC
130 } \
131 while(0)
132#endif
3202e249
VY
133
134#ifdef SOFT_ASSERT
135#define lrb_assert(expr) slrb_assert(expr)
db137867 136#else
3202e249 137#define lrb_assert(expr) do { slrb_assert(expr); assert(expr); } while(0)
db137867
AC
138#endif
139
9d9a4f60 140#ifdef RB_SOCKADDR_HAS_SA_LEN
db137867
AC
141#define ss_len sa_len
142#endif
143
3202e249
VY
144#define GET_SS_FAMILY(x) (((const struct sockaddr *)(x))->sa_family)
145#define SET_SS_FAMILY(x, y) ((((struct sockaddr *)(x))->sa_family) = y)
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
175typedef void log_cb(const char *buffer);
176typedef void restart_cb(const char *buffer);
177typedef void die_cb(const char *buffer);
178
179char *rb_ctime(const time_t, char *, size_t);
180char *rb_date(const time_t, char *, size_t);
181void rb_lib_log(const char *, ...);
182void rb_lib_restart(const char *, ...);
183void rb_lib_die(const char *, ...);
184void rb_set_time(void);
185const char *rb_lib_version(void);
186
187void 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);
189void rb_lib_loop(long delay);
190
191time_t rb_current_time(void);
192const struct timeval *rb_current_time_tv(void);
193pid_t rb_spawn_process(const char *, const char **);
194
195char *rb_strtok_r(char *, const char *, char **);
196
197int rb_gettimeofday(struct timeval *, void *);
198
199void rb_sleep(unsigned int seconds, unsigned int useconds);
200char *rb_crypt(const char *, const char *);
201
202unsigned char *rb_base64_encode(const unsigned char *str, int length);
203unsigned char *rb_base64_decode(const unsigned char *str, int length, int *ret);
3202e249
VY
204int rb_kill(pid_t, int);
205char *rb_strerror(int);
db137867 206
3202e249 207int rb_setenv(const char *, const char *, int);
db137867 208
3202e249
VY
209pid_t rb_waitpid(pid_t pid, int *status, int options);
210pid_t rb_getpid(void);
211//unsigned int rb_geteuid(void);
db137867 212
030272f3 213
db137867
AC
214#include <rb_tools.h>
215#include <rb_memory.h>
216#include <rb_commio.h>
217#include <rb_balloc.h>
218#include <rb_linebuf.h>
219#include <rb_snprintf.h>
220#include <rb_event.h>
221#include <rb_helper.h>
222#include <rb_rawbuf.h>
223#include <rb_patricia.h>
224
225#endif