summaryrefslogtreecommitdiff
path: root/xwrap.c
blob: e2db1167b12610087c331e3ec0de88f3fab61571 (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 <string.h>
#include <stdlib.h>

#include "debug.h"

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

	p = malloc(size);
	if (p == NULL)
		sys_err("malloc %zd bytes", size);
	return p;
}

char *xstrdup(const char *s)
{
	int len;

	if (s == NULL)
		return NULL;

	len = strlen(s) + 1;

	return memcpy(xmalloc(len), s, len);
}