C/C++ Library, mos@ua 1.0
cpplib-mos
hdp.h
Go to the documentation of this file.
1
71#ifndef HDP_H
72#define HDP_H
73
74#include <stdio.h>
75#include <stdlib.h>
76#include <errno.h>
77#include <string.h>
78
79//#define EXCEPTION_POLICY // only for C++
80//#define EXIT_POLICY // DEFAULT
81
82#if defined __cplusplus && defined EXCEPTION_POLICY
83#define MO(func_call) ({\
84 int __MO__result__; \
85 if ((__MO__result__ = (func_call)) == -1) \
86 throw errno; \
87 __MO__result__; \
88 })
89
90#define Ne(func_call) ({\
91 int __Ne__result__; \
92 if ((__Ne__result__ = (func_call)) < 0) \
93 throw errno; \
94 __Ne__result__; \
95 })
96
97#define Nu(func_call) ({\
98 void* __NU__result__; \
99 if ((__NU__result__ = (func_call)) == NULL) \
100 throw errno; \
101 __NU__result__; \
102 })
103
104#define NZ(func_call) ({\
105 int __NZ__result__; \
106 if ((__NZ__result__ = (func_call)) != 0) \
107 throw __NZ__result__; \
108 __NZ__result__; \
109 })
110
111#define EF(func_call) ({\
112 int __EF__result__; \
113 if ((__EF__result__ = (func_call)) == EOF) \
114 throw errno; \
115 __EF__result__; \
116 })
117
118#define MOP(func_call) ({\
119 void* __MOP__result__; \
120 if ((__MOP__result__ = (func_call)) == (void*)-1) \
121 throw errno; \
122 __MOP__result__; \
123 })
124#else
133#define MO(func_call) ({\
134 int __MO__result__; \
135 if ((__MO__result__ = (func_call)) == -1) \
136 do { \
137 fprintf (stderr, "%s at \"%s\":%d: %s\n", \
138 __func__ , __FILE__, __LINE__, strerror (errno)); \
139 *((int*)0) = 0; \
140 abort (); \
141 } while (0); \
142 __MO__result__; \
143 })
144
153#define Ne(func_call) ({\
154 int __Ne__result__; \
155 if ((__Ne__result__ = (func_call)) < 0) \
156 do { \
157 fprintf (stderr, "%s at \"%s\":%d: %s\n", \
158 __func__ , __FILE__, __LINE__, strerror (errno)); \
159 *((int*)0) = 0; \
160 abort (); \
161 } while (0); \
162 __Ne__result__; \
163 })
164
173#define Nu(func_call) ({\
174 void* __Nu__result__; \
175 if ((__Nu__result__ = (func_call)) == NULL) \
176 do { \
177 fprintf (stderr, "%s at \"%s\":%d: %s\n", \
178 __func__ , __FILE__, __LINE__, strerror (errno)); \
179 *((int*)0) = 0; \
180 abort (); \
181 } while (0); \
182 __Nu__result__; \
183 })
184
193#define NZ(func_call) ({\
194 int __NZ__result__; \
195 if ((__NZ__result__ = (func_call)) != 0) \
196 do { \
197 fprintf (stderr, "%s at \"%s\":%d: %s\n", \
198 __func__ , __FILE__, __LINE__, strerror (__NZ__result__)); \
199 *((int*)0) = 0; \
200 abort (); \
201 } while (0); \
202 __NZ__result__; \
203 })
204
213#define EF(func_call) ({\
214 int __EF__result__; \
215 if ((__EF__result__ = (func_call)) == EOF) \
216 do { \
217 fprintf (stderr, "%s at \"%s\":%d: %s\n", \
218 __func__ , __FILE__, __LINE__, strerror (errno)); \
219 *((int*)0) = 0; \
220 abort (); \
221 } while (0); \
222 __EF__result__; \
223 })
224
233#define MOP(func_call) ({\
234 void* __MOP__result__; \
235 if ((__MOP__result__ = (func_call)) == (void*)-1) \
236 do { \
237 fprintf (stderr, "%s at \"%s\":%d: %s\n", \
238 __func__ , __FILE__, __LINE__, strerror (errno)); \
239 *((int*)0) = 0; \
240 abort (); \
241 } while (0); \
242 __MOP__result__; \
243 })
244#endif
245
249#define errMO MO
253#define errNe Ne
257#define errNu Nu
261#define errNZ NZ
265#define errEF EF
269#define errMOP MOP
270
271#endif
272
273/* ************************************************** */
277/* ************************************************** */
278