mtrand: remove it and replace with simpler, generic code
[netsniff-ng.git] / die.h
blobf45814f38c45d47033600d00b4ef37a709684d6a
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Subject to the GPL, version 2.
6 */
8 #ifndef DIE_H
9 #define DIE_H
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <stdarg.h>
14 #include <string.h>
15 #include <errno.h>
16 #include <unistd.h>
17 #include <syslog.h>
19 #include "built_in.h"
21 static inline void panic(const char *format, ...) __check_format_printf(1, 2);
22 static inline void syslog_panic(const char *format,
23 ...) __check_format_printf(1, 2);
24 static inline void syslog_maybe(int may, int priority,
25 const char *format, ...) __check_format_printf(3, 4);
26 static inline void whine(const char *format, ...) __check_format_printf(1, 2);
27 static inline void verbose_l1(const char *format,
28 ...) __check_format_printf(1, 2);
29 static inline void verbose_l2(const char *format,
30 ...) __check_format_printf(1, 2);
32 static inline void die(void)
34 exit(EXIT_FAILURE);
37 static inline void _die(void)
39 _exit(EXIT_FAILURE);
42 static inline void panic(const char *format, ...)
44 va_list vl;
46 va_start(vl, format);
47 vfprintf(stderr, format, vl);
48 va_end(vl);
50 die();
53 static inline void syslog_panic(const char *format, ...)
55 va_list vl;
57 va_start(vl, format);
58 vsyslog(LOG_ERR, format, vl);
59 va_end(vl);
61 die();
64 static inline void syslog_maybe(int may, int priority, const char *format, ...)
66 if (!!may) {
67 va_list vl;
69 va_start(vl, format);
70 vsyslog(priority, format, vl);
71 va_end(vl);
75 static inline void whine(const char *format, ...)
77 va_list vl;
79 va_start(vl, format);
80 vfprintf(stderr, format, vl);
81 va_end(vl);
84 extern int verbose_level;
86 static inline void verbose_l1(const char *format, ...)
88 va_list vl;
90 if (verbose_level < 1)
91 return;
93 va_start(vl, format);
94 vfprintf(stderr, format, vl);
95 va_end(vl);
98 static inline void verbose_l2(const char *format, ...)
100 va_list vl;
102 if (verbose_level < 2)
103 return;
105 va_start(vl, format);
106 vfprintf(stderr, format, vl);
107 va_end(vl);
110 #endif /* DIE_H */