2
Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
18
#define EC_INIT int ret = 0
19
#define EC_STATUS(a) ret = (a)
20
#define EC_FAIL ret = -1; goto cleanup
21
#define EC_CLEANUP cleanup
22
#define EC_EXIT return ret
25
* Check out doc/DEVELOPER for more infos.
27
* We have these macros:
28
* EC_ZERO, EC_ZERO_LOG, EC_ZERO_LOGSTR, EC_ZERO_LOG_ERR, EC_ZERO_CUSTOM
29
* EC_NEG1, EC_NEG1_LOG, EC_NEG1_LOGSTR, EC_NEG1_LOG_ERR, EC_NEG1_CUSTOM
30
* EC_NULL, EC_NULL_LOG, EC_NULL_LOGSTR, EC_NULL_LOG_ERR, EC_NULL_CUSTOM
32
* A boileplate function template is:
47
/* check for return val 0 which is ok, every other is an error, prints errno */
48
#define EC_ZERO_LOG(a) \
51
LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
57
#define EC_ZERO_LOGSTR(a, b, ...) \
60
LOG(log_error, logtype_default, b, __VA_ARGS__); \
66
#define EC_ZERO_LOG_ERR(a, b) \
69
LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
83
#define EC_ZERO_ERR(a,b ) \
91
/* check for return val 0 which is ok, every other is an error, prints errno */
92
#define EC_NEG1_LOG(a) \
95
LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
101
#define EC_NEG1_LOGSTR(a, b, ...) \
104
LOG(log_error, logtype_default, b, __VA_ARGS__); \
110
#define EC_NEG1_LOG_ERR(a, b) \
113
LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
127
/* check for return val != NULL, prints errno */
128
#define EC_NULL_LOG(a) \
131
LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
137
#define EC_NULL_LOGSTR(a, b, ...) \
140
LOG(log_error, logtype_default, b , __VA_ARGS__); \
146
#define EC_NULL_LOG_ERR(a, b) \
149
LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
163
#endif /* ERRCHECK_H */