diff options
author | Preston Pan <ret2pop@gmail.com> | 2024-12-28 16:47:43 -0800 |
---|---|---|
committer | Preston Pan <ret2pop@gmail.com> | 2024-12-28 16:47:43 -0800 |
commit | 1fd608288ee47c2c560817f12f14b21069fed2f6 (patch) | |
tree | e6460b92dba5bb0d089c8c2a4e794e3504098359 /src/common/helpers.c | |
parent | 63f11aaec8d21844a07fd27003a992c102a3a297 (diff) |
makefile and directory structure change completely to build client and server
Diffstat (limited to 'src/common/helpers.c')
-rw-r--r-- | src/common/helpers.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/common/helpers.c b/src/common/helpers.c new file mode 100644 index 0000000..4bf7301 --- /dev/null +++ b/src/common/helpers.c @@ -0,0 +1,36 @@ +#include "../include/helpers.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +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); } + +void nothing(void *_) {} |