ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/memory.c
Revision: 6357
Committed: Mon Aug 17 16:38:13 2015 UTC (10 years ago) by michael
Content type: text/x-csrc
File size: 2182 byte(s)
Log Message:
- Make server_die() use enum; minor cleanups here and there

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 "ircd_defs.h"
29     #include "irc_string.h"
30     #include "memory.h"
31 michael 1309 #include "log.h"
32 adx 30 #include "restart.h"
33    
34    
35     /*
36 michael 3504 * MyCalloc - allocate memory, call outofmemory on failure
37 adx 30 */
38     void *
39 michael 3504 MyCalloc(size_t size)
40 adx 30 {
41     void *ret = calloc(1, size);
42    
43     if (ret == NULL)
44     outofmemory();
45 michael 1011
46     return ret;
47 adx 30 }
48    
49     /*
50     * MyRealloc - reallocate memory, call outofmemory on failure
51     */
52     void *
53     MyRealloc(void *x, size_t y)
54     {
55     void *ret = realloc(x, y);
56    
57 michael 4473 if (y && ret == NULL)
58 adx 30 outofmemory();
59 michael 1011
60     return ret;
61 adx 30 }
62    
63     void
64     MyFree(void *x)
65     {
66 michael 5425 free(x);
67 adx 30 }
68    
69 michael 1646 void *
70     xstrdup(const char *s)
71 adx 30 {
72 michael 1646 void *ret = malloc(strlen(s) + 1);
73    
74     if (ret == NULL)
75     outofmemory();
76    
77     strcpy(ret, s);
78    
79     return ret;
80 adx 30 }
81    
82 michael 1646 void *
83     xstrndup(const char *s, size_t len)
84     {
85     void *ret = malloc(len + 1);
86    
87     if (ret == NULL)
88     outofmemory();
89    
90     strlcpy(ret, s, len + 1);
91    
92     return ret;
93     }
94    
95 adx 30 /* outofmemory()
96     *
97     * input - NONE
98     * output - NONE
99     * side effects - simply try to report there is a problem.
100     * Abort if it was called more than once
101     */
102     void
103     outofmemory(void)
104     {
105     static int was_here = 0;
106    
107 michael 1011 if (was_here++)
108 adx 30 abort();
109    
110 michael 1247 ilog(LOG_TYPE_IRCD, "Out of memory: restarting server...");
111 michael 6357 server_die("Out of Memory", SERVER_RESTART);
112 adx 30 }

Properties

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