blob: 42f81b024b82939b566ae14731fdba8b22937f5c [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001
2#ifndef UTIL_H
3#define UTIL_H
4
5void warn(const char *inMessage, const char *inFile, int inLine);
6void warn_errno(const char *inMessage, const char *inFile, int inLine);
7
8#define FAIL(cond, msg) \
9 do { \
10 if (cond) { \
11 warn(msg, __FILE__, __LINE__); \
12 exit(1); \
13 } \
14 } while(0)
15
16#define FAIL_errno(cond, msg) \
17 do { \
18 if (cond) { \
19 warn_errno(msg, __FILE__, __LINE__); \
20 exit(1); \
21 } \
22 } while( 0 )
23
24#define WARN( cond, msg ) \
25 do { \
26 if ( cond ) { \
27 warn( msg, __FILE__, __LINE__ ); \
28 } \
29 } while( 0 )
30
31#define WARN_errno( cond, msg ) \
32 do { \
33 if ( cond ) { \
34 warn_errno( msg, __FILE__, __LINE__ ); \
35 } \
36 } while( 0 )
37
38/* -------------------------------------------------------------------
39 * delete macro
40 * ------------------------------------------------------------------- */
41/*
42#define DELETE_PTR( ptr ) \
43 do { \
44 if ( ptr != NULL ) { \
45 delete ptr; \
46 ptr = NULL; \
47 } \
48 } while( false )
49
50#define DELETE_ARRAY( ptr ) \
51 do { \
52 if ( ptr != NULL ) { \
53 delete [] ptr; \
54 ptr = NULL; \
55 } \
56 } while( false )
57*/
58#endif /* UTIL_H */