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 do { ret = -1; goto cleanup; } while (0)
21 #define EC_FAIL_LOG(a, ...) \
23 LOG(log_error, logtype_default, a, __VA_ARGS__); \
27 #define EC_CLEANUP cleanup
28 #define EC_EXIT return ret
31 * Check out doc/DEVELOPER for more infos.
33 * We have these macros:
34 * EC_ZERO, EC_ZERO_LOG, EC_ZERO_LOGSTR, EC_ZERO_LOG_ERR, EC_ZERO_CUSTOM
35 * EC_NEG1, EC_NEG1_LOG, EC_NEG1_LOGSTR, EC_NEG1_LOG_ERR, EC_NEG1_CUSTOM
36 * EC_NULL, EC_NULL_LOG, EC_NULL_LOGSTR, EC_NULL_LOG_ERR, EC_NULL_CUSTOM
38 * A boileplate function template is:
53 /* check for return val 0 which is ok, every other is an error, prints errno */
54 #define EC_ZERO_LOG(a) \
57 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
63 #define EC_ZERO_LOGSTR(a, b, ...) \
66 LOG(log_error, logtype_default, b, __VA_ARGS__); \
72 #define EC_ZERO_LOG_ERR(a, b) \
75 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
89 #define EC_ZERO_ERR(a,b ) \
97 /* check for return val 0 which is ok, every other is an error, prints errno */
98 #define EC_NEG1_LOG(a) \
101 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
107 #define EC_NEG1_LOGSTR(a, b, ...) \
110 LOG(log_error, logtype_default, b, __VA_ARGS__); \
116 #define EC_NEG1_LOG_ERR(a, b) \
119 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
133 /* check for return val != NULL, prints errno */
134 #define EC_NULL_LOG(a) \
137 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
143 #define EC_NULL_LOGSTR(a, b, ...) \
146 LOG(log_error, logtype_default, b , __VA_ARGS__); \
152 #define EC_NULL_LOG_ERR(a, b) \
155 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
169 #endif /* ERRCHECK_H */