aboutsummaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-12-17 16:27:23 -0800
committerBruce Hill <bruce@bruce-hill.com>2020-12-17 16:27:23 -0800
commit484e1e33da7477b7278c9a3e9da878f0375dd75b (patch)
tree892979f8bf65fd9a1366c040fa4a090968fcaecf /utils.h
parent40be243004b095fe15bb2ece176692f8354cdf45 (diff)
Memory allocation failure checks, and a simpler new() function
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/utils.h b/utils.h
index bd79e3f..61c817f 100644
--- a/utils.h
+++ b/utils.h
@@ -14,6 +14,9 @@
// TODO: better error reporting
#define check(cond, ...) do { if (!(cond)) { fprintf(stderr, __VA_ARGS__); fwrite("\n", 1, 1, stderr); _exit(1); } } while(0)
#define debug(...) do { if (verbose) fprintf(stderr, __VA_ARGS__); } while(0)
+#define new(t) memcheck(calloc(sizeof(t), 1))
+#define xcalloc(a,b) memcheck(calloc(a,b))
+#define xrealloc(a,b) memcheck(realloc(a,b))
__attribute__((nonnull))
unsigned char unescapechar(const char *escaped, const char **end);
@@ -25,6 +28,7 @@ __attribute__((nonnull))
int matchchar(const char **str, char c);
__attribute__((nonnull))
size_t unescape_string(char *dest, const char *src, size_t bufsize);
+void *memcheck(void *p);
#endif
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1