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_CLEANUP cleanup
21 #define EC_EXIT return ret
24 * Check out doc/DEVELOPER for more infos.
26 * We have these macros:
27 * EC_ZERO, EC_ZERO_LOG, EC_ZERO_LOG_ERR, EC_ZERO_CUSTOM
28 * EC_NEG1, EC_NEG1_LOG, EC_NEG1_LOG_ERR, EC_NEG1_CUSTOM
29 * EC_NULL, EC_NULL_LOG, EC_NULL_LOG_ERR, EC_NULL_CUSTOM
31 * A boileplate function template is:
46 /* check for return val 0 which is ok, every other is an error, prints errno */
47 #define EC_ZERO_LOG(a) \
50 LOG(log_error, logtype_default, "%s failed: %s" #a, strerror(errno)); \
56 #define EC_ZERO_LOG_ERR(a, b) \
59 LOG(log_error, logtype_default, "%s failed: %s" #a, strerror(errno)); \
65 /* check for return val 0 which is ok, every other is an error */
74 /* check for return val 0 which is ok, every other is an error */
75 #define EC_ZERO_CUSTOM(a) \
78 /* check for return val 0 which is ok, every other is an error, prints errno */
79 #define EC_NEG1_LOG(a) \
82 LOG(log_error, logtype_default, "%s failed: %s" #a, strerror(errno)); \
88 #define EC_NEG1_LOG_ERR(a, b) \
91 LOG(log_error, logtype_default, "%s failed: %s" #a, strerror(errno)); \
97 /* check for return val 0 which is ok, every other is an error */
106 #define EC_NEG1_CUSTOM(a) \
109 /* check for return val != NULL, prints errno */
110 #define EC_NULL_LOG(a) \
113 LOG(log_error, logtype_default, "%s failed: %s" #a, strerror(errno)); \
119 #define EC_NULL_LOG_ERR(a, b) \
122 LOG(log_error, logtype_default, "%s failed: %s" #a, strerror(errno)); \
128 /* check for return val != NULL */
137 #define EC_NULL_CUSTOM(a) \
140 #endif /* ERRCHECK_H */