summaryrefslogtreecommitdiff
path: root/src/shared.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared.h')
-rw-r--r--src/shared.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/shared.h b/src/shared.h
index 3c23676..ee3e06b 100644
--- a/src/shared.h
+++ b/src/shared.h
@@ -2,9 +2,8 @@
2#define __VXGG_REWRITE___SHARED_H___3880294315821___ 2#define __VXGG_REWRITE___SHARED_H___3880294315821___
3 3
4#include <stddef.h> 4#include <stddef.h>
5#include <stdarg.h>
6 5
7#define STATICARR_SIZE(arr) (sizeof((arr))/sizeof((arr)[0])) 6#define STATIC_ARRAY_LEN(arr) (sizeof((arr))/sizeof((arr)[0]))
8 7
9// Defines how `x___alloc()` functions should exit. `___VXGG___XALLOC_EXIT_ON_ERROR___ > 0` calls `error()`, and thus functions 8// Defines how `x___alloc()` functions should exit. `___VXGG___XALLOC_EXIT_ON_ERROR___ > 0` calls `error()`, and thus functions
10// registered with `atexit()` and `on_exit()`. `___VXGG___XALLOC_EXIT_ON_ERROR___ <= 0` calls `abort()` on error. `x___alloc()` 9// registered with `atexit()` and `on_exit()`. `___VXGG___XALLOC_EXIT_ON_ERROR___ <= 0` calls `abort()` on error. `x___alloc()`
@@ -15,6 +14,16 @@
15// `___VXGG___VERBOSE_ERRORS___ > 0` will print diagnostic error messages, and will do nothing otherwise 14// `___VXGG___VERBOSE_ERRORS___ > 0` will print diagnostic error messages, and will do nothing otherwise
16#define ___VXGG___VERBOSE_ERRORS___ 1 15#define ___VXGG___VERBOSE_ERRORS___ 1
17 16
17// Macro to exit on an alloc error instead of doing the terrible nested if statement that was being used previously
18#define XALLOC_EXIT(msg, ...) do {\
19 if(!___VXGG___XALLOC_EXIT_ON_ERROR___)\
20 abort();\
21 if(!___VXGG___VERBOSE_ERRORS___)\
22 exit(EXIT_FAILURE);\
23 error(EXIT_FAILURE, errno, (msg)__VA_ARGS__);\
24 exit(EXIT_FAILURE); /* Makes gcc happy */\
25} while (0)
26
18// `calloc()` with error checking. Calls `error()` or `abort()` on error, depending on the value of `___VXGG___XALLOC_EXIT_ON_ERROR___` 27// `calloc()` with error checking. Calls `error()` or `abort()` on error, depending on the value of `___VXGG___XALLOC_EXIT_ON_ERROR___`
19void* xcalloc(size_t nmemb, size_t size); 28void* xcalloc(size_t nmemb, size_t size);
20 29