1998-04-22 12:58:34 +00:00
|
|
|
/*
|
|
|
|
* BIRD Library
|
|
|
|
*
|
2000-03-07 21:04:14 +00:00
|
|
|
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
|
1998-04-22 12:58:34 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BIRD_BIRDLIB_H_
|
|
|
|
#define _BIRD_BIRDLIB_H_
|
|
|
|
|
|
|
|
/* Ugly structure offset handling macros */
|
|
|
|
|
|
|
|
#define OFFSETOF(s, i) ((unsigned int)&((s *)0)->i)
|
|
|
|
#define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i)))
|
1998-05-03 16:43:39 +00:00
|
|
|
#define ALIGN(s, a) (((s)+a-1)&~(a-1))
|
|
|
|
|
1999-02-05 21:29:19 +00:00
|
|
|
/* Utility macros */
|
|
|
|
|
|
|
|
#define MIN(a,b) (((a)<(b))?(a):(b))
|
|
|
|
#define MAX(a,b) (((a)>(b))?(a):(b))
|
2002-11-13 08:47:19 +00:00
|
|
|
#define ABS(a) ((a)>=0 ? (a) : -(a))
|
2000-04-12 13:21:23 +00:00
|
|
|
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))
|
1998-07-09 19:36:05 +00:00
|
|
|
|
1999-03-29 19:13:36 +00:00
|
|
|
#ifndef NULL
|
|
|
|
#define NULL ((void *) 0)
|
|
|
|
#endif
|
|
|
|
|
1998-05-03 16:43:39 +00:00
|
|
|
/* Functions which don't return */
|
|
|
|
|
|
|
|
#define NORET __attribute__((noreturn))
|
1998-04-22 12:58:34 +00:00
|
|
|
|
1998-04-23 14:01:15 +00:00
|
|
|
/* Logging and dying */
|
|
|
|
|
1998-07-10 08:39:34 +00:00
|
|
|
void log(char *msg, ...);
|
|
|
|
void die(char *msg, ...) NORET;
|
1998-12-20 14:24:35 +00:00
|
|
|
void bug(char *msg, ...) NORET;
|
1998-04-23 14:01:15 +00:00
|
|
|
|
|
|
|
#define L_DEBUG "\001" /* Debugging messages */
|
1998-12-20 14:24:35 +00:00
|
|
|
#define L_TRACE "\002" /* Protocol tracing */
|
|
|
|
#define L_INFO "\003" /* Informational messages */
|
|
|
|
#define L_REMOTE "\004" /* Remote protocol errors */
|
2001-02-20 09:49:19 +00:00
|
|
|
#define L_WARN "\005" /* Local warnings */
|
|
|
|
#define L_ERR "\006" /* Local errors */
|
|
|
|
#define L_AUTH "\007" /* Authorization failed etc. */
|
|
|
|
#define L_FATAL "\010" /* Fatal errors */
|
|
|
|
#define L_BUG "\011" /* BIRD bugs */
|
1998-05-03 16:43:39 +00:00
|
|
|
|
|
|
|
void debug(char *msg, ...); /* Printf to debug output */
|
1998-04-23 14:01:15 +00:00
|
|
|
|
|
|
|
/* Debugging */
|
|
|
|
|
2000-03-07 21:04:14 +00:00
|
|
|
#if defined(LOCAL_DEBUG) || defined(GLOBAL_DEBUG)
|
1998-05-26 21:36:17 +00:00
|
|
|
#define DBG(x, y...) debug(x, ##y)
|
1998-04-23 14:01:15 +00:00
|
|
|
#else
|
2000-03-12 21:47:25 +00:00
|
|
|
#define DBG(x, y...) do { } while(0)
|
1998-04-23 14:01:15 +00:00
|
|
|
#endif
|
|
|
|
|
1998-12-20 14:24:35 +00:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
#define ASSERT(x) do { if (!(x)) bug("Assertion `%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0)
|
|
|
|
#else
|
|
|
|
#define ASSERT(x) do { } while(0)
|
|
|
|
#endif
|
|
|
|
|
1999-08-17 20:47:40 +00:00
|
|
|
/* Pseudorandom numbers */
|
|
|
|
|
|
|
|
u32 random_u32(void);
|
|
|
|
|
1998-04-22 12:58:34 +00:00
|
|
|
#endif
|