Statistics
| Branch: | Revision:

iof-bird-daemon / lib / birdlib.h @ 25697773

History | View | Annotate | Download (1.23 KB)

1
/*
2
 *        BIRD Library
3
 *
4
 *        (c) 1998 Martin Mares <mj@ucw.cz>
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)))
16
#define ALIGN(s, a) (((s)+a-1)&~(a-1))
17

    
18
/* Functions which don't return */
19

    
20
#define NORET __attribute__((noreturn))
21

    
22
/* Logging and dying */
23

    
24
void log(char *msg, ...) __attribute__((format(printf,1,2)));
25
void die(char *msg, ...) __attribute__((format(printf,1,2))) NORET;
26

    
27
#define L_DEBUG "\001"                        /* Debugging messages */
28
#define L_INFO "\002"                        /* Informational messages */
29
#define L_WARN "\003"                        /* Warnings */
30
#define L_ERR "\004"                        /* Errors */
31
#define L_AUTH "\005"                        /* Authorization failed etc. */
32
#define L_FATAL "\006"                        /* Fatal errors */
33

    
34
void log_init(char *);                        /* Initialize logging to given file (NULL=stderr, ""=syslog) */
35
void log_init_debug(char *);                /* Initialize debug dump to given file (NULL=stderr, ""=off) */
36

    
37
void debug(char *msg, ...);                /* Printf to debug output */
38

    
39
/* Debugging */
40

    
41
#ifdef LOCAL_DEBUG
42
#define DBG(x, y...) log(L_DEBUG x, ##y)
43
#else
44
#define DBG(x, y...)
45
#endif
46

    
47
#endif