summaryrefslogtreecommitdiffstats
path: root/support/nfs/xmalloc.c
blob: 9523afc4aa5cceebcaf5d5a9255ac536472c8411 (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
42
43
44
45
46
47
48
/*
 * support/nfs/xmalloc.c
 *
 * malloc with NULL checking.
 *
 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
 */

#include "config.h"

#include <stdlib.h>
#include <string.h>
#include "xmalloc.h"
#include "xlog.h"

void *
xmalloc(size_t size)
{
	void	*ptr;

	if (!(ptr = malloc(size)))
		xlog(L_FATAL, "malloc: out of memory");
	return ptr;
}

void *
xrealloc(void *ptr, size_t size)
{
	if (!(ptr = realloc(ptr, size)))
		xlog(L_FATAL, "realloc: out of memory");
	return ptr;
}

void
xfree(void *ptr)
{
	free(ptr);
}

char *
xstrdup(const char *str)
{
	char	*ret;

	if (!(ret = strdup(str)))
		xlog(L_FATAL, "strdup: out of memory");
	return ret;
}