ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/memory.c
Revision: 5052
Committed: Mon Dec 22 11:56:03 2014 UTC (10 years, 8 months ago) by michael
Content type: text/x-csrc
Original Path: hopm/trunk/src/malloc.c
File size: 1577 byte(s)
Log Message:
- Initial import of bopm 3.1.3

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    
73     char *DupString(const char *y)
74     {
75     char *x;
76    
77     x = malloc(strlen(y) + 1);
78     assert(x);
79     strcpy(x, y);
80    
81     return x;
82     }