From 63f11aaec8d21844a07fd27003a992c102a3a297 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Fri, 27 Dec 2024 20:05:06 -0800 Subject: make directory structure for client --- server/helpers.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 server/helpers.c (limited to 'server/helpers.c') diff --git a/server/helpers.c b/server/helpers.c new file mode 100644 index 0000000..8485dc6 --- /dev/null +++ b/server/helpers.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +void die_lz(int code, const char *msg) { + if (code < 0) { + die(msg); + } +} + +void die(const char *msg) { + fprintf(stderr, "panic: "); + perror(msg); + exit(EXIT_FAILURE); +} + +void *safe_calloc(unsigned int i, size_t size) { + void *x = calloc(i, size); + if (x == NULL) { + die("abort: calloc()"); + } + return x; +} + +void *safe_realloc(void *x, size_t size) { + void *p = realloc(x, size); + if (x == NULL) { + die("abort: realloc()"); + } + return p; +} + +void alloc_zero(void *ptr, size_t size) { memset(ptr, 0, size); } -- cgit