netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
errchk.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
3
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.
8
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.
13 */
14
15#ifndef ERRCHECK_H
16#define ERRCHECK_H
17
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(...) \
23 do { \
24 LOG(log_error, logtype_default, __VA_ARGS__); \
25 ret = -1; \
26 goto cleanup; \
27 } while (0)
28#define EC_CLEANUP cleanup
29#define EC_EXIT return ret
30
59
61#define EC_ZERO_LOG(a) \
62 do { \
63 if ((a) != 0) { \
64 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
65 ret = -1; \
66 goto cleanup; \
67 } \
68 } while (0)
69
70#define EC_ZERO_LOGSTR(a, b, ...) \
71 do { \
72 if ((a) != 0) { \
73 LOG(log_error, logtype_default, b, __VA_ARGS__); \
74 ret = -1; \
75 goto cleanup; \
76 } \
77 } while (0)
78
79#define EC_ZERO_LOG_ERR(a, b) \
80 do { \
81 if ((a) != 0) { \
82 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
83 ret = (b); \
84 goto cleanup; \
85 } \
86 } while (0)
87
88#define EC_ZERO(a) \
89 do { \
90 if ((a) != 0) { \
91 ret = -1; \
92 goto cleanup; \
93 } \
94 } while (0)
95
96#define EC_ZERO_ERR(a,b ) \
97 do { \
98 if ((a) != 0) { \
99 ret = b; \
100 goto cleanup; \
101 } \
102 } while (0)
103
105#define EC_NEG1_LOG(a) \
106 do { \
107 if ((a) == -1) { \
108 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
109 ret = -1; \
110 goto cleanup; \
111 } \
112 } while (0)
113
114#define EC_NEG1_LOGSTR(a, b, ...) \
115 do { \
116 if ((a) == -1) { \
117 LOG(log_error, logtype_default, b, __VA_ARGS__); \
118 ret = -1; \
119 goto cleanup; \
120 } \
121 } while (0)
122
123#define EC_NEG1_LOG_ERR(a, b) \
124 do { \
125 if ((a) == -1) { \
126 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
127 ret = b; \
128 goto cleanup; \
129 } \
130 } while (0)
131
132#define EC_NEG1(a) \
133 do { \
134 if ((a) == -1) { \
135 ret = -1; \
136 goto cleanup; \
137 } \
138 } while (0)
139
141#define EC_NULL_LOG(a) \
142 do { \
143 if ((a) == NULL) { \
144 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
145 ret = -1; \
146 goto cleanup; \
147 } \
148 } while (0)
149
150#define EC_NULL_LOGSTR(a, b, ...) \
151 do { \
152 if ((a) == NULL) { \
153 LOG(log_error, logtype_default, b , __VA_ARGS__); \
154 ret = -1; \
155 goto cleanup; \
156 } \
157 } while (0)
158
159#define EC_NULL_LOG_ERR(a, b) \
160 do { \
161 if ((a) == NULL) { \
162 LOG(log_error, logtype_default, "%s failed: %s", #a, strerror(errno)); \
163 ret = b; \
164 goto cleanup; \
165 } \
166 } while (0)
167
168#define EC_NULL(a) \
169 do { \
170 if ((a) == NULL) { \
171 ret = -1; \
172 goto cleanup; \
173 } \
174 } while (0)
175
176#endif /* ERRCHECK_H */