ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/memory.C
Revision: 1.5
Committed: Tue Aug 28 17:12:24 2007 UTC (19 years ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +1 -1 lines
State: FILE REMOVED
Log Message:
removed old files

File Contents

# User Rev Content
1 pippijn 1.1 /**
2     * Copyright © 2005 Atheme Development Group
3 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
4 pippijn 1.1 *
5     * Memory functions.
6     */
7    
8 pippijn 1.5 static char const rcsid[] = "$Id: memory.C,v 1.4 2007-07-25 00:03:21 pippijn Exp $";
9 pippijn 1.1
10     #include "atheme.h"
11    
12 pippijn 1.4 std::vector<void *> gc::mortals;
13    
14 pippijn 1.1 /* does malloc()'s job and dies if malloc() fails */
15     void *
16     smalloc (size_t size)
17     {
18     void *buf = calloc (size, 1);
19    
20     if (!buf)
21     raise (SIGUSR1);
22     return buf;
23     }
24    
25     /* does calloc()'s job and dies if calloc() fails */
26     void *
27     scalloc (size_t elsize, size_t els)
28     {
29     void *buf = calloc (elsize, els);
30    
31     if (!buf)
32     raise (SIGUSR1);
33     return buf;
34     }
35    
36     /* does realloc()'s job and dies if realloc() fails */
37     void *
38     srealloc (void *oldptr, size_t newsize)
39     {
40     void *buf = realloc (oldptr, newsize);
41    
42     if (!buf)
43     raise (SIGUSR1);
44     return buf;
45     }
46    
47     /* does strdup()'s job, only with the above memory functions */
48     char *
49     sstrdup (char const *s)
50     {
51     char *t;
52    
53     if (s == NULL)
54     return NULL;
55    
56     t = static_cast < char *>(smalloc (strlen (s) + 1));
57    
58     strcpy (t, s);
59     return t;
60     }
61    
62     /* does strndup()'s job, only with the above memory functions */
63     char *
64     sstrndup (char const *s, int len)
65     {
66     char *t;
67    
68     if (s == NULL)
69     return NULL;
70    
71     t = static_cast < char *>(smalloc (len + 1));
72    
73     strlcpy (t, s, len);
74     return t;
75     }