Removed files, reorganized code i.e. renamed write_or_die.c to xutils.c
[transsip.git] / src / die.h
bloba8d036ed6214c82087c3631b088f4de8ae9adc14
1 /*
2 * transsip - the telephony network
3 * By Daniel Borkmann <daniel@transsip.org>
4 * Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5 * Swiss federal institute of technology (ETH Zurich)
6 * Subject to the GPL, version 2.
7 */
9 #ifndef DIE_H
10 #define DIE_H
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <stdarg.h>
15 #include <string.h>
16 #include <errno.h>
17 #include <syslog.h>
19 #include "compiler.h"
21 static inline void error_and_die(int status, char *msg, ...)
23 va_list vl;
24 va_start(vl, msg);
25 vfprintf(stderr, msg, vl);
26 va_end(vl);
27 exit(status);
30 static inline void die(void)
32 exit(EXIT_FAILURE);
35 static inline void panic(char *msg, ...)
37 va_list vl;
38 va_start(vl, msg);
39 vfprintf(stderr, msg, vl);
40 va_end(vl);
41 die();
44 #define syslog_panic(msg...) \
45 do { \
46 syslog(LOG_ERR, ##msg); \
47 die(); \
48 } while (0)
50 static inline void whine(char *msg, ...)
52 va_list vl;
53 va_start(vl, msg);
54 vfprintf(stderr, msg, vl);
55 va_end(vl);
58 #define syslog_whine(msg...) \
59 do { \
60 syslog(LOG_WARNING, ##msg); \
61 } while (0)
63 static inline void info(char *msg, ...)
65 va_list vl;
66 va_start(vl, msg);
67 vfprintf(stdout, msg, vl);
68 va_end(vl);
71 #define syslog_info(msg...) \
72 do { \
73 syslog(LOG_INFO, ##msg); \
74 } while (0)
76 static inline void BUG(char *msg, ...)
78 va_list vl;
79 whine("BUG: ");
80 va_start(vl, msg);
81 vfprintf(stderr, msg, vl);
82 va_end(vl);
83 die();
86 static inline void BUG_ON(int cond, char *msg, ...)
88 va_list vl;
89 if (unlikely(cond)) {
90 whine("BUG: ");
91 va_start(vl, msg);
92 vfprintf(stderr, msg, vl);
93 va_end(vl);
94 die();
98 #ifdef _DEBUG_
99 static inline void debug(char *msg, ...)
101 va_list vl;
102 va_start(vl, msg);
103 vfprintf(stderr, msg, vl);
104 va_end(vl);
105 fflush(stderr);
107 #else
108 static inline void debug(char *msg, ...)
110 /* NOP */
112 #endif /* _DEBUG_ */
114 static inline void puke_and_die(int status, char *msg, ...)
116 va_list vl;
117 va_start(vl, msg);
118 vfprintf(stderr, msg, vl);
119 va_end(vl);
121 fprintf(stderr, ": %s\n", strerror(errno));
123 exit(status);
126 #endif /* DIE_H */