cleaned up stuff, added dht lib
[netyack.git] / src / die.h
blob715ae6b4481493ff25fe76491f3199d0cca0ae22
1 /*
2 * netyack
3 * By Daniel Borkmann <daniel@netyack.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Subject to the GPL.
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>
17 #include "tty.h"
19 static inline void error_and_die(int status, char *msg, ...)
21 va_list vl;
22 va_start(vl, msg);
23 vfprintf(stderr, msg, vl);
24 va_end(vl);
26 exit(status);
29 static inline void die(void)
31 exit(EXIT_FAILURE);
34 static inline void panic(char *msg, ...)
36 va_list vl;
37 va_start(vl, msg);
38 vfprintf(stderr, msg, vl);
39 va_end(vl);
41 die();
44 static inline void whine(char *msg, ...)
46 va_list vl;
47 va_start(vl, msg);
48 vfprintf(stderr, msg, vl);
49 va_end(vl);
52 static inline void info(char *msg, ...)
54 va_list vl;
55 va_start(vl, msg);
56 vfprintf(stdout, msg, vl);
57 va_end(vl);
60 #ifdef _DEBUG_
61 static inline void debug(char *msg, ...)
63 va_list vl;
64 va_start(vl, msg);
65 vfprintf(stderr, msg, vl);
66 va_end(vl);
68 fflush(stderr);
71 static inline void debug_blue(char *msg, ...)
73 va_list vl;
75 fprintf(stderr, "%s", colorize_start_full(white, blue));
76 va_start(vl, msg);
77 vfprintf(stderr, msg, vl);
78 va_end(vl);
79 fprintf(stderr, "%s\n", colorize_end());
81 fflush(stderr);
84 static inline void debug_red(char *msg, ...)
86 va_list vl;
88 fprintf(stderr, "%s", colorize_start_full(white, red));
89 va_start(vl, msg);
90 vfprintf(stderr, msg, vl);
91 va_end(vl);
92 fprintf(stderr, "%s\n", colorize_end());
94 fflush(stderr);
97 static inline void debug_green(char *msg, ...)
99 va_list vl;
101 fprintf(stderr, "%s", colorize_start_full(white, green));
102 va_start(vl, msg);
103 vfprintf(stderr, msg, vl);
104 va_end(vl);
105 fprintf(stderr, "%s\n", colorize_end());
107 fflush(stderr);
109 #else
110 static inline void debug(char *msg, ...)
112 /* NOP */
115 static inline void debug_blue(char *msg, ...)
117 /* NOP */
120 static inline void debug_red(char *msg, ...)
122 /* NOP */
125 static inline void debug_green(char *msg, ...)
127 /* NOP */
129 #endif /* _DEBUG_ */
131 static inline void print_blue(char *msg, ...)
133 va_list vl;
135 fprintf(stdout, "%s", colorize_start_full(white, blue));
136 va_start(vl, msg);
137 vfprintf(stdout, msg, vl);
138 va_end(vl);
139 fprintf(stdout, "%s\n", colorize_end());
141 fflush(stdout);
144 static inline void print_red(char *msg, ...)
146 va_list vl;
148 fprintf(stdout, "%s", colorize_start_full(white, red));
149 va_start(vl, msg);
150 vfprintf(stdout, msg, vl);
151 va_end(vl);
152 fprintf(stdout, "%s\n", colorize_end());
154 fflush(stdout);
157 static inline void print_green(char *msg, ...)
159 va_list vl;
161 fprintf(stdout, "%s", colorize_start_full(white, green));
162 va_start(vl, msg);
163 vfprintf(stdout, msg, vl);
164 va_end(vl);
165 fprintf(stdout, "%s\n", colorize_end());
167 fflush(stdout);
170 static inline void puke_and_die_num(int status, int num, char *msg, ...)
172 va_list vl;
173 va_start(vl, msg);
174 vfprintf(stderr, msg, vl);
175 va_end(vl);
177 fprintf(stderr, ": %s\n", strerror(num));
179 exit(status);
182 static inline void puke_and_die(int status, char *msg, ...)
184 va_list vl;
185 va_start(vl, msg);
186 vfprintf(stderr, msg, vl);
187 va_end(vl);
189 fprintf(stderr, ": %s\n", strerror(errno));
191 exit(status);
194 #endif /* DIE_H */