summaryrefslogtreecommitdiff
path: root/fitz/base_memory.c
blob: 3209b33382b479ad745af67feaf8a7d30c4a019d (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "fitz.h"

void * fz_malloc(int n)
{
	void *p = malloc(n);
	if (!p)
	{
		fprintf(stderr, "fatal error: out of memory\n");
		abort();
	}
	return p;
}

void * fz_realloc(void *p, int n)
{
	void *np = realloc(p, n);
	if (np == nil)
	{
		fprintf(stderr, "fatal error: out of memory\n");
		abort();
	}
	return np;
}

void fz_free(void *p)
{
	free(p);
}

char * fz_strdup(char *s)
{
	char *ns = malloc(strlen(s) + 1);
	if (!ns)
	{
		fprintf(stderr, "fatal error: out of memory\n");
		abort();
	}
	memcpy(ns, s, strlen(s) + 1);
	return ns;
}