src/lib/error.h
branchnew-lib-errors
changeset 218 5229a5d098b2
parent 217 7728d6ec3abf
child 219 cefec18b8268
--- a/src/lib/error.h	Wed May 27 23:57:48 2009 +0300
+++ b/src/lib/error.h	Thu May 28 00:35:02 2009 +0300
@@ -12,6 +12,7 @@
  * then be used to trace the error down.
  */
 #include <stdbool.h>
+#include <errno.h>
 
 /**
  * The type used to represent a scalar error code, there are only unique per level.
@@ -112,7 +113,7 @@
  * Helper macro to define an error_list
  */
 #define ERROR_LIST(name, ...) \
-    { (name), __VA_ARGS__, ERROR_TYPE_END }
+    { (name), { __VA_ARGS__, ERROR_TYPE_END } }
 
 /**
  * Maximum number of nesting levels supported for errors
@@ -185,7 +186,7 @@
 /**
  * Evaluates to the current top of the error stack, 
  */
-static struct error_item* error_top (error_t *err)
+static inline struct error_item* error_top (error_t *err)
 {
     return err->cur ? err->cur : err->stack;
 }
@@ -267,26 +268,17 @@
 /**
  * Abort execution of process with error message
  */
-void _error_abort (const char *file, const char *line, const char *func, const char *fmt, ...);
+void _error_abort (const char *file, int line, const char *func, const char *fmt, ...);
 #define error_abort(...) _error_abort(__FILE__, __LINE__, __func__, __VA_ARGS__);
 
 /**
  * Used to mark unexpcted conditions for switch-default. The given val must be an integer, as passed to switch
  */
-#define NOT_REACHED(val) error_abort("%s = %#x", #val, (int) (val));
+#define NOT_REACHED(val) error_abort("%s = %d", #val, (int) (val));
 
-/**
- * General-purpose errors that may be useful and don't belong in any more specific namespace.
+/*
+ * Include some common error codes
  */
-enum general_error_code {
-    ERR_GENERAL_NONE,
-    ERR_MEM,                ///< memory allocation error
-    ERR_NOT_IMPLEMENTED,    ///< function not implmented: <func>
-    ERR_MISC,               ///< miscellaneous error: <error>
-    ERR_CMD_OPT,            ///< invalid command line option: <error> - XXX: replace with something getopt
-    ERR_UNKNOWN,            ///< unknown error
-};
-
-const struct error_list general_errors;
+#include "errors.h"
 
 #endif /* LIBQMSK_ERROR_H */