summaryrefslogtreecommitdiff
path: root/fitz/base_memory.c
blob: 1f224ddbe31e91544d9c12ae3c22e1973a9c3377 (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
#include "fitz_base.h"

void * fz_malloc(int n)
{
    void *p = malloc(n);
    if (!p)
	fz_throw("cannot malloc %d bytes", n);
    return p;
}

void * fz_realloc(void *p, int n)
{
    void *np = realloc(p, n);
    if (np == nil)
	fz_throw("cannot realloc %d bytes", n);
    return np;
}

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

char * fz_strdup(char *s)
{
    char *ns = malloc(strlen(s) + 1);
    if (!ns)
	fz_throw("cannot strdup %lu bytes", (unsigned long)strlen(s) + 1);
    memcpy(ns, s, strlen(s) + 1);
    return ns;
}