ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/branches/1.1.x/src/memory.c
Revision: 8562
Committed: Sun Sep 23 11:39:20 2018 UTC (7 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 1529 byte(s)
Log Message:
- Update copyright years

File Contents

# User Rev Content
1 michael 5052 /*
2 michael 5351 * Copyright (c) 2002 Erik Fears
3 michael 8562 * Copyright (c) 2014-2018 ircd-hybrid development team
4 michael 5052 *
5 michael 5351 * 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 michael 5052 *
10 michael 5351 * 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 michael 5052 *
15 michael 5351 * 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 michael 5052 */
20    
21 michael 5335 #include <stdlib.h>
22 michael 5052 #include <assert.h>
23     #include <string.h>
24    
25 michael 5333 #include "memory.h"
26 michael 5052
27 michael 5333
28 michael 5274 /* xcalloc
29 michael 5876 *
30 michael 5052 * A wrapper function for malloc(), for catching memory issues
31     * and error handling.
32     *
33     * Parameters
34     * bytes: amount in bytes to allocate
35 michael 5876 *
36 michael 5052 * Return:
37     * Pointer to allocated memory
38     */
39 michael 5916 void *
40     xcalloc(size_t bytes)
41 michael 5052 {
42     void *ret = calloc(1, bytes);
43     assert(ret);
44    
45     return ret;
46     }
47    
48 michael 5426 /* xfree
49 michael 5052 *
50 michael 5274 * Free memory allocated with xcalloc
51 michael 5052 *
52     * Parameters:
53     * var: pointer to memory to free
54 michael 5876 *
55 michael 5052 * Return:
56     * None
57     */
58 michael 5916 void
59     xfree(void *ptr)
60 michael 5052 {
61 michael 5426 free(ptr);
62 michael 5052 }
63    
64 michael 5092 void *
65     xstrdup(const char *s)
66 michael 5052 {
67 michael 5092 void *ret = malloc(strlen(s) + 1);
68 michael 5052
69 michael 5092 assert(ret);
70     strcpy(ret, s);
71 michael 5052
72 michael 5092 return ret;
73 michael 5052 }

Properties

Name Value
svn:eol-style native
svn:keywords Id