]> git.ipfire.org Git - thirdparty/bird.git/blame - lib/birdlib.h
Added paper for my talk about BIRD at SLT 2001.
[thirdparty/bird.git] / lib / birdlib.h
CommitLineData
58ef912c
MM
1/*
2 * BIRD Library
3 *
3cbfcafe 4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
58ef912c
MM
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9#ifndef _BIRD_BIRDLIB_H_
10#define _BIRD_BIRDLIB_H_
11
12/* Ugly structure offset handling macros */
13
14#define OFFSETOF(s, i) ((unsigned int)&((s *)0)->i)
15#define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i)))
18c8241a
MM
16#define ALIGN(s, a) (((s)+a-1)&~(a-1))
17
c4c63eec
MM
18/* Utility macros */
19
20#define MIN(a,b) (((a)<(b))?(a):(b))
21#define MAX(a,b) (((a)>(b))?(a):(b))
77506349 22#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))
cf3527e2 23
61340248
MM
24#ifndef NULL
25#define NULL ((void *) 0)
26#endif
27
18c8241a
MM
28/* Functions which don't return */
29
30#define NORET __attribute__((noreturn))
58ef912c 31
c40e05a0
MM
32/* Logging and dying */
33
1be52eea
MM
34void log(char *msg, ...);
35void die(char *msg, ...) NORET;
98e87c86 36void bug(char *msg, ...) NORET;
c40e05a0
MM
37
38#define L_DEBUG "\001" /* Debugging messages */
98e87c86
MM
39#define L_TRACE "\002" /* Protocol tracing */
40#define L_INFO "\003" /* Informational messages */
41#define L_REMOTE "\004" /* Remote protocol errors */
42#define L_WARN "\004" /* Local warnings */
43#define L_ERR "\005" /* Local errors */
44#define L_AUTH "\006" /* Authorization failed etc. */
45#define L_FATAL "\007" /* Fatal errors */
46#define L_BUG "\010" /* BIRD bugs */
18c8241a 47
18c8241a 48void debug(char *msg, ...); /* Printf to debug output */
c40e05a0
MM
49
50/* Debugging */
51
3cbfcafe 52#if defined(LOCAL_DEBUG) || defined(GLOBAL_DEBUG)
5222c46c 53#define DBG(x, y...) debug(x, ##y)
c40e05a0 54#else
e68dd11c 55#define DBG(x, y...) do { } while(0)
c40e05a0
MM
56#endif
57
98e87c86
MM
58#ifdef DEBUGGING
59#define ASSERT(x) do { if (!(x)) bug("Assertion `%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0)
60#else
61#define ASSERT(x) do { } while(0)
62#endif
63
f6519414
MM
64/* Pseudorandom numbers */
65
66u32 random_u32(void);
67
58ef912c 68#endif