aboutsummaryrefslogtreecommitdiff
path: root/src/xalloc.c
blob: 6ab68020cb12a0dc07bdf9bc04cb43e0453d9954 (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
49
50
51
52
53
54
55
56
57
58
/* This file is part of vmod-binlog
   Copyright (C) 2013 Sergey Poznyakoff

   Vmod-binlog is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   Vmod-binlog is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with vmod-binlog.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <config.h>
#include <stdlib.h>
#include <string.h>
#include "xalloc.h"
#include "err.h"

void *
xmalloc(size_t s)
{
	void *p = malloc(s);
	if (!p) {
		error("out of memory");
		exit(1);
	}
	return p;
}

void *
xcalloc(size_t count, size_t size)
{
	void *p;
	
	size *= count;
	p = xmalloc(count * size);
	memset(p, 0, size);
	return p;
}

void *
xmemdup(void const *p, size_t s)
{
	return memcpy(xmalloc(s), p, s);
}

char *
xstrdup(const char *s)
{
	return xmemdup(s, strlen(s) + 1);
}

 

Return to:

Send suggestions and report system problems to the System administrator.