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_EXIT_STATUS(a) do { ret = (a); goto cleanup; } while (0)
21 #define EC_FAIL do { ret = -1; goto cleanup; } while (0)
22 #define EC_FAIL_LOG(...) \
24 LOG(log_error, logtype_default, __VA_ARGS__); \
28 #define EC_CLEANUP cleanup
29 #define EC_EXIT return ret
32 * Check out doc/DEVELOPER for more infos.
34 * We have these macros:
35 * EC_ZERO, EC_ZERO_LOG, EC_ZERO_LOGSTR, EC_ZERO_LOG_ERR, EC_ZERO_CUSTOM
36 * EC_NEG1, EC_NEG1_LOG, EC_NEG1_LOGSTR, EC_NEG1_LOG_ERR, EC_NEG1_CUSTOM
37 * EC_NULL, EC_NULL_LOG, EC_NULL_LOGSTR, EC_NULL_LOG_ERR, EC_NULL_CUSTOM
39 * A boileplate function template is:
54 /* check for return val 0 which is ok, every other is an error, prints errno */
55 #define EC_ZERO_LOG(a) \
58 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
64 #define EC_ZERO_LOGSTR(a, b, ...) \
67 LOG(log_error, logtype_default, b, __VA_ARGS__); \
73 #define EC_ZERO_LOG_ERR(a, b) \
76 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
90 #define EC_ZERO_ERR(a,b ) \
98 /* check for return val 0 which is ok, every other is an error, prints errno */
99 #define EC_NEG1_LOG(a) \
102 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
108 #define EC_NEG1_LOGSTR(a, b, ...) \
111 LOG(log_error, logtype_default, b, __VA_ARGS__); \
117 #define EC_NEG1_LOG_ERR(a, b) \
120 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
134 /* check for return val != NULL, prints errno */
135 #define EC_NULL_LOG(a) \
138 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
144 #define EC_NULL_LOGSTR(a, b, ...) \
147 LOG(log_error, logtype_default, b , __VA_ARGS__); \
153 #define EC_NULL_LOG_ERR(a, b) \
156 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
170 #endif /* ERRCHECK_H */