lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | |
| 2 | #ifndef UTIL_H |
| 3 | #define UTIL_H |
| 4 | |
| 5 | void warn(const char *inMessage, const char *inFile, int inLine); |
| 6 | void 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 */ |