--- a/common.h Fri Jun 06 18:35:46 2008 +0300
+++ b/common.h Fri Jun 06 23:37:45 2008 +0300
@@ -3,32 +3,25 @@
* error handling
*/
-// perror + exit
-void die (const char *msg);
-
-// fprintf + newline
-void error (const char *fmt, ...);
-
-// fprintf + strerror + newline
-void perr (const char *fmt, ...);
+void _generic_err (const char *func, int perr, int do_exit, const char *fmt, ...);
-// fprintf + strerror + newline + exit
-void perr_exit (const char *fmt, ...);
-
-// fprintf + newline + exit
-void err_exit (const char *fmt, ...);
-
-// fprintf (__func__ + msg, ...)
-void err_func (const char *func, const char *fmt, ...);
-
-// fprintf (__func__ + msg + strerror, ...)
-void perr_func (const char *func, const char *fmt, ...);
+// various kinds of ways to handle an error, 2**3 of them, *g*
+#define error(...) _generic_err(NULL, 0, 0, __VA_ARGS__)
+#define err_exit(...) _generic_err(NULL, 0, 1, __VA_ARGS__)
+#define perr(...) _generic_err(NULL, 1, 0, __VA_ARGS__)
+#define perr_exit(...) _generic_err(NULL, 1, 1, __VA_ARGS__)
+#define err_func(func, ...) _generic_err(func, 0, 0, __VA_ARGS__)
+#define err_func_exit(func, ...) _generic_err(func, 0, 1, __VA_ARGS__)
+#define perr_func(func, ...) _generic_err(func, 1, 0, __VA_ARGS__)
+#define perr_func_exit(func, ...) _generic_err(func, 1, 1, __VA_ARGS__)
// error(func + colon + msg, ...) + goto error
-#define ERROR(msg) do { err_func(__func__, "%s", msg); goto error; } while (0)
-#define ERROR_FMT(fmt, ...) do { err_func(__func__, fmt, __VA_ARGS__); goto error; } while (0)
-#define PERROR(msg) do { perr_func(__func__, "%s", msg); goto error; } while (0)
-#define PERROR_FMT(fmt, ...) do { perr_func(__func__, fmt, __VA_ARGS__); goto error; } while (0)
+#define ERROR(...) do { err_func(__func__, __VA_ARGS__); goto error; } while (0)
+#define PERROR(...) do { perr_func(__func__, __VA_ARGS__); goto error; } while (0)
+#define FATAL(...) err_func_exit(__func__, __VA_ARGS__)
+#define PFATAL(...) perr_func_exit(__func__, __VA_ARGS__)
+#define WARNING(...) err_func(__func__, __VA_ARGS__)
+#define PWARNING(...) perr_func(__func__, __VA_ARGS__)
/*
* Parse a host:port string.