ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/malloc.c
Revision: 5092
Committed: Tue Dec 23 20:12:39 2014 UTC (9 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 1573 byte(s)
Log Message:
- Renamed DupString() to xstrdup()

File Contents

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