csnip  0.1
err.h
Go to the documentation of this file.
1 #ifndef CSNIP_ERR_H
2 #define CSNIP_ERR_H
3 
35 #ifndef csnip_err_Unhandled
36 #include <stdio.h>
37 #include <stdlib.h>
44 #define csnip_err_Unhandled(errnumber) \
45  do { \
46  char buf[128]; \
47  csnip_err_str(errnumber, buf, sizeof(buf)); \
48  fprintf(stderr, "%s:%d: %s\n", \
49  __FILE__, \
50  __LINE__, \
51  buf); \
52  _Exit(127); \
53  } while(0)
54 #endif
55 
78 #define csnip_err_Raise(value, err_expr) \
79  do { \
80  int _, error_ignore; \
81  (void)_; (void)error_ignore; \
82  _Pragma("GCC diagnostic ignored \"-Waddress\""); \
83  if (0 == &(err_expr) || &_ == &(err_expr)) { \
84  csnip_err_Unhandled(value); \
85  } \
86  (err_expr) = (value); \
87  } while(0)
88 
92 #define csnip_err_SUCCESS 0
93 #define csnip_err_ERRNO (-1)
94 #define csnip_err_NOMEM (-2)
95 #define csnip_err_UNDERFLOW (-3)
96 #define csnip_err_RANGE (-4)
97 #define csnip_err_FORMAT (-5)
98 #define csnip_err_UNEXPECTED_NULL (-6)
99 #define csnip_err_INVAL (-7)
100 #define csnip_err_CALLFLOW (-8)
103 #ifdef __cplusplus
104 extern "C" {
105 #endif
106 
121 void csnip_err_str(int errnum, char* buf, size_t buf_len);
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
129 #endif /* CSNIP_ERR_H */
130 
131 #if defined(CSNIP_SHORT_NAMES) && !defined(CSNIP_ERR_HAVE_SHORT_NAMES)
132 #define err_Unhandled csnip_err_Unhandled
133 #define err_str csnip_err_str
134 #define err_SUCCESS csnip_err_SUCCESS
135 #define err_ERRNO csnip_err_ERRNO
136 #define err_NOMEM csnip_err_NOMEM
137 #define err_UNDERFLOW csnip_err_UNDERFLOW
138 #define err_RANGE csnip_err_RANGE
139 #define err_FORMAT csnip_err_FORMAT
140 #define err_UNEXPECTED_NULL csnip_err_UNEXPECTED_NULL
141 #define err_INVAL csnip_err_INVAL
142 #define err_CALLFLOW csnip_err_CALLFLOW
143 #define CSNIP_ERR_HAVE_SHORT_NAMES
144 #endif /* CSNIP_SHORT_NAMES && !CSNIP_ERR_HAVE_SHORT_NAMES */
void csnip_err_str(int errnum, char *buf, size_t buf_len)
Return a descriptive error string.
Definition: err.c:38