ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/memory.c
Revision: 6885
Committed: Tue Dec 1 19:50:56 2015 UTC (9 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 2080 byte(s)
Log Message:
- Remove unused header includes

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2916 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 5347 * Copyright (c) 1997-2015 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2916 /*! \file memory.c
23     * \brief Memory utilities.
24     * \version $Id$
25     */
26 adx 30
27     #include "stdinc.h"
28     #include "irc_string.h"
29     #include "memory.h"
30     #include "restart.h"
31    
32    
33     /*
34 michael 3504 * MyCalloc - allocate memory, call outofmemory on failure
35 adx 30 */
36     void *
37 michael 3504 MyCalloc(size_t size)
38 adx 30 {
39     void *ret = calloc(1, size);
40    
41     if (ret == NULL)
42     outofmemory();
43 michael 1011
44     return ret;
45 adx 30 }
46    
47     /*
48     * MyRealloc - reallocate memory, call outofmemory on failure
49     */
50     void *
51     MyRealloc(void *x, size_t y)
52     {
53     void *ret = realloc(x, y);
54    
55 michael 4473 if (y && ret == NULL)
56 adx 30 outofmemory();
57 michael 1011
58     return ret;
59 adx 30 }
60    
61     void
62     MyFree(void *x)
63     {
64 michael 5425 free(x);
65 adx 30 }
66    
67 michael 1646 void *
68     xstrdup(const char *s)
69 adx 30 {
70 michael 1646 void *ret = malloc(strlen(s) + 1);
71    
72     if (ret == NULL)
73     outofmemory();
74    
75     strcpy(ret, s);
76    
77     return ret;
78 adx 30 }
79    
80 michael 1646 void *
81     xstrndup(const char *s, size_t len)
82     {
83     void *ret = malloc(len + 1);
84    
85     if (ret == NULL)
86     outofmemory();
87    
88     strlcpy(ret, s, len + 1);
89    
90     return ret;
91     }
92    
93 adx 30 /* outofmemory()
94     *
95     * input - NONE
96     * output - NONE
97     * side effects - simply try to report there is a problem.
98     * Abort if it was called more than once
99     */
100     void
101     outofmemory(void)
102     {
103     static int was_here = 0;
104    
105 michael 1011 if (was_here++)
106 adx 30 abort();
107    
108 michael 6556 server_die("out of memory", SERVER_RESTART);
109 adx 30 }

Properties

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