equal
deleted
inserted
replaced
1 #include "error.h" |
1 #include "error.h" |
2 #include "log.h" |
2 #include "log.h" |
|
3 |
|
4 const struct error_list general_errors = ERROR_LIST("general", |
|
5 ERROR_TYPE( ERR_MEM, "memory allocation error" ), |
|
6 ERROR_TYPE_STRING( ERR_NOT_IMPLEMENTED, "function not implmented" ), |
|
7 ERROR_TYPE_STRING( ERR_MISC, "miscellaneous error" ), |
|
8 ERROR_TYPE_STRING( ERR_CMD_OPT, "invalid command line option" ), |
|
9 ERROR_TYPE( ERR_UNKNOWN, "unknown error" ) |
|
10 ); |
3 |
11 |
4 const struct error_type* error_lookup_code (const struct error_list *list, err_t code) |
12 const struct error_type* error_lookup_code (const struct error_list *list, err_t code) |
5 { |
13 { |
6 const struct error_type *type; |
14 const struct error_type *type; |
7 |
15 |
41 |
49 |
42 // return what we found |
50 // return what we found |
43 return type; |
51 return type; |
44 } |
52 } |
45 |
53 |
46 const char* error_name (const error_t *err) |
54 const char* error_name (const struct error_list *list, err_t code); |
47 { |
55 { |
48 struct error_type *type; |
56 struct error_type *type; |
49 |
57 |
50 // just do a lookup |
58 // just do a lookup |
51 if ((type = error_lookup(err))) |
59 if ((type = error_lookup_code(list, code))) |
52 return "[unknown]"; |
60 return "[unknown]"; |
53 |
61 |
54 else |
62 else |
55 return type->name; |
63 return type->name; |
56 } |
64 } |
117 { |
125 { |
118 // XXX: implement |
126 // XXX: implement |
119 return true; |
127 return true; |
120 } |
128 } |
121 |
129 |
|
130 void error_reset (error_t *err) |
|
131 { |
|
132 memset(err, 0, sizeof(*err)); |
|
133 } |
|
134 |
122 /** |
135 /** |
123 * Advance error stack to next position, and return pointer. |
136 * Advance error stack to next position, and return pointer. |
124 * |
137 * |
125 * Returns NULL if the stack runs out of space. |
138 * Returns NULL if the stack runs out of space. |
126 */ |
139 */ |