1 |
/* |
2 |
* Copyright (c) 2002 Erik Fears |
3 |
* Copyright (c) 2014-2015 ircd-hybrid development team |
4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
7 |
* the Free Software Foundation; either version 2 of the License, or |
8 |
* (at your option) any later version. |
9 |
* |
10 |
* This program is distributed in the hope that it will be useful, |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
* GNU General Public License for more details. |
14 |
* |
15 |
* You should have received a copy of the GNU General Public License |
16 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
18 |
* USA |
19 |
*/ |
20 |
|
21 |
#include <stdlib.h> |
22 |
#include <assert.h> |
23 |
#include <string.h> |
24 |
|
25 |
#include "memory.h" |
26 |
|
27 |
|
28 |
/* xcalloc |
29 |
* |
30 |
* A wrapper function for malloc(), for catching memory issues |
31 |
* and error handling. |
32 |
* |
33 |
* Parameters |
34 |
* bytes: amount in bytes to allocate |
35 |
* |
36 |
* Return: |
37 |
* Pointer to allocated memory |
38 |
*/ |
39 |
void * |
40 |
xcalloc(size_t bytes) |
41 |
{ |
42 |
void *ret = calloc(1, bytes); |
43 |
assert(ret); |
44 |
|
45 |
return ret; |
46 |
} |
47 |
|
48 |
/* xfree |
49 |
* |
50 |
* Free memory allocated with xcalloc |
51 |
* |
52 |
* Parameters: |
53 |
* var: pointer to memory to free |
54 |
* |
55 |
* Return: |
56 |
* None |
57 |
*/ |
58 |
void |
59 |
xfree(void *ptr) |
60 |
{ |
61 |
free(ptr); |
62 |
} |
63 |
|
64 |
void * |
65 |
xstrdup(const char *s) |
66 |
{ |
67 |
void *ret = malloc(strlen(s) + 1); |
68 |
|
69 |
assert(ret); |
70 |
strcpy(ret, s); |
71 |
|
72 |
return ret; |
73 |
} |