diff options
Diffstat (limited to 'comp/lucas-standen-NEA/code/tokenizer/util.c')
-rw-r--r-- | comp/lucas-standen-NEA/code/tokenizer/util.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/comp/lucas-standen-NEA/code/tokenizer/util.c b/comp/lucas-standen-NEA/code/tokenizer/util.c new file mode 100644 index 0000000..de5b6b2 --- /dev/null +++ b/comp/lucas-standen-NEA/code/tokenizer/util.c @@ -0,0 +1,27 @@ +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <error.h> + +void Die(); // brings down the program +void *CheckedMalloc(long size); // malloc checked +void *CheckedRealloc(void *out, long size); // realloc checked + +void Die(){ + perror("zpy parser"); + exit(errno); +} + +void *CheckedMalloc(long size){ + void *out = malloc(size); + if (out == NULL) + Die(); + return out; +} + +void *CheckedRealloc(void *orig, long size){ + void *out = realloc(orig, size); + if (out == NULL) + Die(); + return out; +} |