chiark / gitweb /
disobedience, playrtp: Have `playrtp' handle volume control.
[disorder] / lib / log.h
index 5d39732d7f2996adadd6b4a395af7f22fc837191..d1445cfc17745923cda2c1911aadcc1831d0e34f 100644 (file)
--- a/lib/log.h
+++ b/lib/log.h
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder.
- * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
+ * Copyright (C) 2004, 2005, 2007-9, 2013 Richard Kettlewell
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -28,12 +28,41 @@ struct log_output;
 
 void set_progname(char **argv);
 
-void elog(int pri, int errno_value, const char *fmt, va_list ap);
+/** @brief Possible error number spaces */
+enum error_class {
+  /** @brief Invalid number space */
+  ec_none,
 
+  /** @brief @c errno number space */
+  ec_errno,
+
+  /** @brief Windows GetLastError/WSAGetLastError return value */
+  ec_windows,
+
+  /** @brief getaddrinfo() return value */
+  ec_getaddrinfo,
+};
+
+#if _WIN32
+# define ec_native ec_windows
+# define ec_socket ec_windows
+#else
+# define ec_native ec_errno
+# define ec_socket ec_errno
+#endif
+
+void elog(int pri, enum error_class, int errno_value, const char *fmt, va_list ap);
+
+declspec(noreturn)
 void disorder_fatal(int errno_value, const char *msg, ...) attribute((noreturn))
   attribute((format (printf, 2, 3)));
+declspec(noreturn)
+void disorder_fatal_ec(enum error_class ec, int errno_value, const char *msg, ...) attribute((noreturn))
+  attribute((format (printf, 3, 4)));
 void disorder_error(int errno_value, const char *msg, ...)
   attribute((format (printf, 2, 3)));
+void disorder_error_ec(enum error_class ec, int errno_value, const char *msg, ...)
+  attribute((format (printf, 3, 4)));
 void disorder_info(const char *msg, ...)
   attribute((format (printf, 1, 2)));
 void disorder_debug(const char *msg, ...)
@@ -41,17 +70,7 @@ void disorder_debug(const char *msg, ...)
 /* report a message of the given class.  @errno_value@ if present an
  * non-zero is included.  @fatal@ terminates the process. */
 
-/** @brief Backward-compatibility alias for disorder_fatal() */
-#define fatal disorder_fatal
-
-/** @brief Backward-compatibility alias for disorder_error() */
-#define error disorder_error
-
-/** @brief Backward-compatibility alias for disorder_info() */
-#define info disorder_info
-
-/** @brief Backward-compatibility alias for disorder_debug() */
-#define debug disorder_debug
+const char *format_error(enum error_class ec, int err, char buffer[], size_t bufsize);
 
 extern int debugging;
 /* set when debugging enabled */
@@ -62,18 +81,26 @@ extern void (*exitfn)(int) attribute((noreturn));
 extern const char *progname;
 /* program name */
 
-extern struct log_output log_stderr, log_syslog, *log_default;
+extern struct log_output log_stderr, *log_default;
+#if HAVE_SYSLOG_H
+extern struct log_output log_syslog;
+#endif
 /* some typical outputs */
 
 extern const char *debug_filename;
 extern int debug_lineno;
 extern int logdate;
 
+/** @brief Issue a debug message if debugging is turned on
+ * @param x Parenthesized debug arguments
+ *
+ * Use in the format: D(("format string", arg, arg, ...));
+ */
 #define D(x) do {                              \
   if(debugging) {                              \
     debug_filename=__FILE__;                   \
     debug_lineno=__LINE__;                     \
-    debug x;                                   \
+    disorder_debug x;                          \
   }                                            \
 } while(0)