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 result; \
85 if ((result = (func_call)) == -1) \
86 throw errno; \
87 result; \
88 })
89
90#define Ne(func_call) ({\
91 int result; \
92 if ((result = (func_call)) < 0) \
93 throw errno; \
94 result; \
95 })
96
97#define Nu(func_call) ({\
98 void* result; \
99 if ((result = (func_call)) == NULL) \
100 throw errno; \
101 result; \
102 })
103
104#define NZ(func_call) ({\
105 int result; \
106 if ((result = (func_call)) != 0) \
107 throw result; \
108 result; \
109 })
110
111#define EF(func_call) ({\
112 int result; \
113 if ((result = (func_call)) == EOF) \
114 throw errno; \
115 result; \
116 })
117
118#define MOP(func_call) ({\
119 void* result; \
120 if ((result = (func_call)) == (void*)-1) \
121 throw errno; \
122 result; \
123 })
124#else
133#define MO(func_call) ({\
134 int result; \
135 if ((result = (func_call)) == -1) \
136 do { \
137 fprintf (stderr, "%s at \"%s\":%d: %s\n", \
138 __FUNCTION__ , __FILE__, __LINE__, strerror (errno)); \
139 *((int*)0) = 0; \
140 abort (); \
141 } while (0); \
142 result; \
143 })
144
153#define Ne(func_call) ({\
154 int result; \
155 if ((result = (func_call)) < 0) \
156 do { \
157 fprintf (stderr, "%s at \"%s\":%d: %s\n", \
158 __FUNCTION__ , __FILE__, __LINE__, strerror (errno)); \
159 *((int*)0) = 0; \
160 abort (); \
161 } while (0); \
162 result; \
163 })
164
173#define Nu(func_call) ({\
174 void* result; \
175 if ((result = (func_call)) == NULL) \
176 do { \
177 fprintf (stderr, "%s at \"%s\":%d: %s\n", \
178 __FUNCTION__ , __FILE__, __LINE__, strerror (errno)); \
179 *((int*)0) = 0; \
180 abort (); \
181 } while (0); \
182 result; \
183 })
184
193#define NZ(func_call) ({\
194 int result; \
195 if ((result = (func_call)) != 0) \
196 do { \
197 fprintf (stderr, "%s at \"%s\":%d: %s\n", \
198 __FUNCTION__ , __FILE__, __LINE__, strerror (result)); \
199 *((int*)0) = 0; \
200 abort (); \
201 } while (0); \
202 result; \
203 })
204
213#define EF(func_call) ({\
214 int result; \
215 if ((result = (func_call)) == EOF) \
216 do { \
217 fprintf (stderr, "%s at \"%s\":%d: %s\n", \
218 __FUNCTION__ , __FILE__, __LINE__, strerror (errno)); \
219 *((int*)0) = 0; \
220 abort (); \
221 } while (0); \
222 result; \
223 })
224
233#define MOP(func_call) ({\
234 void* result; \
235 if ((result = (func_call)) == (void*)-1) \
236 do { \
237 fprintf (stderr, "%s at \"%s\":%d: %s\n", \
238 __FUNCTION__ , __FILE__, __LINE__, strerror (errno)); \
239 *((int*)0) = 0; \
240 abort (); \
241 } while (0); \
242 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