summaryrefslogtreecommitdiff
path: root/comp/lucas-standen-NEA/code/tokenizer/util.c
blob: de5b6b26897991ec789c261470ad7a9e11981662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}