ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/memory.c
Revision: 31
Committed: Sun Oct 2 20:34:05 2005 UTC (19 years, 10 months ago) by knight
Content type: text/x-csrc
Original Path: ircd-hybrid/src/memory.c
File size: 2036 byte(s)
Log Message:
- Fix svn:keywords

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * memory.c: Memory utilities.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25    
26     #include "stdinc.h"
27     #include "ircd_defs.h"
28     #include "ircd.h"
29     #include "irc_string.h"
30     #include "memory.h"
31     #include "list.h"
32     #include "client.h"
33     #include "send.h"
34     #include "tools.h"
35     #include "s_log.h"
36     #include "restart.h"
37    
38    
39     /*
40     * MyMalloc - allocate memory, call outofmemory on failure
41     */
42     void *
43     MyMalloc(size_t size)
44     {
45     void *ret = calloc(1, size);
46    
47     if (ret == NULL)
48     outofmemory();
49     return(ret);
50     }
51    
52     /*
53     * MyRealloc - reallocate memory, call outofmemory on failure
54     */
55     void *
56     MyRealloc(void *x, size_t y)
57     {
58     void *ret = realloc(x, y);
59    
60     if (ret == NULL)
61     outofmemory();
62     return(ret);
63     }
64    
65     void
66     MyFree(void *x)
67     {
68     if (x)
69     free(x);
70     }
71    
72     void
73     _DupString(char **x, const char *y)
74     {
75     (*x) = malloc(strlen(y) + 1);
76     strcpy((*x), y);
77     }
78    
79     /* outofmemory()
80     *
81     * input - NONE
82     * output - NONE
83     * side effects - simply try to report there is a problem.
84     * Abort if it was called more than once
85     */
86     void
87     outofmemory(void)
88     {
89     static int was_here = 0;
90    
91     if (was_here)
92     abort();
93    
94     was_here = 1;
95    
96     ilog(L_CRIT, "Out of memory: restarting server...");
97     restart("Out of Memory");
98     }

Properties

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