From 5365f8fa8d6ebfbf3ba92816abe55a99feff6f25 Mon Sep 17 00:00:00 2001 From: Jack Jamison Date: Wed, 22 Jul 2026 09:09:18 -0400 Subject: clean up --- snag/src/util.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 snag/src/util.h (limited to 'snag/src/util.h') diff --git a/snag/src/util.h b/snag/src/util.h new file mode 100644 index 0000000..3813903 --- /dev/null +++ b/snag/src/util.h @@ -0,0 +1,31 @@ +#ifndef UTIL_H +#define UTIL_H + +#include +#include + +// utility for errors +#if !DEBUG + void log(const char* format, ...) __attribute__((format(printf, 1, 2))); + void die(const char* format, ...) __attribute__((format(printf, 1, 2))); + void* emalloc(size_t size, char* alloc_reason); +#else + #define log(fmt, ...) _log(__LINE__, __FILE__, fmt, ##__VA_ARGS__) + void _log(int line, const char* file, const char* format, ...) __attribute__((format(printf, 3, 4))); + + #define die(fmt, ...) _die(__LINE__, __FILE__, fmt, ##__VA_ARGS__) + void _die(int line, const char* file, const char* format, ...) __attribute__((format(printf, 3, 4))); + + #define emalloc(size, alloc_reason) _emalloc(__LINE__, __FILE__, size, alloc_reason) + void* _emalloc(int line, const char* file, size_t size, char* alloc_reason); +#endif + +// functions for outputting and displaying text +#define printout(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__) +#define print(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) + +// string functions +char* vastrcat_(int dummy, ...); +#define vastrcat(...) vastrcat_(0, __VA_ARGS__, NULL) + +#endif -- cgit v1.2.3