ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/memory.C
Revision: 1.1
Committed: Thu Jul 19 08:24:59 2007 UTC (16 years, 10 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import. the most important changes since Atheme are:
- fixed many memory leaks
- fixed many bugs
- converted to C++ and use more STL containers
- added a (not very enhanced yet) perl module
- greatly improved XML-RPC speed
- added a JSON-RPC module with code from json-cpp
- added a valgrind memcheck module to operserv
- added a more object oriented base64 implementation
- added a specialised unit test framework
- improved stability
- use gettimeofday() if available
- reworked adding/removing commands
- MemoServ IGNORE DEL can now remove indices

File Contents

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