summaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
authorsvn svn@31f1291d-b8d6-0310-a050-a5561fc1590b <svn svn@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864>2004-03-28 21:59:56 +0000
committersvn svn@31f1291d-b8d6-0310-a050-a5561fc1590b <svn svn@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864>2004-03-28 21:59:56 +0000
commit55bf4dbcabf378e9472b7d31d6edf87f6ac853e9 (patch)
tree7a9454ea6b8750256e242cf6d5fba3ca7a4b5044 /memory.c
Initial Anope Import
git-svn-id: svn://svn.anope.org/anope/trunk@1 31f1291d-b8d6-0310-a050-a5561fc1590b git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/memory.c b/memory.c
new file mode 100644
index 000000000..5bfcf395b
--- /dev/null
+++ b/memory.c
@@ -0,0 +1,96 @@
+/* Memory management routines.
+ *
+ * (C) 2003 Anope Team
+ * Contact us at info@anope.org
+ *
+ * Please read COPYING and README for furhter details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ *
+ * $Id: memory.c,v 1.7 2003/07/20 01:15:49 dane Exp $
+ *
+ */
+
+#include "services.h"
+
+/*************************************************************************/
+/*************************************************************************/
+
+/* smalloc, scalloc, srealloc, sstrdup:
+ * Versions of the memory allocation functions which will cause the
+ * program to terminate with an "Out of memory" error if the memory
+ * cannot be allocated. (Hence, the return value from these functions
+ * is never NULL.)
+ */
+
+void *smalloc(long size)
+{
+ void *buf;
+
+ if (!size) {
+ size = 1;
+ }
+ buf = malloc(size);
+ if (!buf)
+#if !defined(USE_THREADS) || !defined(LINUX20)
+ raise(SIGUSR1);
+#else
+ abort();
+#endif
+ return buf;
+}
+
+void *scalloc(long elsize, long els)
+{
+ void *buf;
+
+ if (!elsize || !els) {
+ elsize = els = 1;
+ }
+ buf = calloc(elsize, els);
+ if (!buf)
+#if !defined(USE_THREADS) || !defined(LINUX20)
+ raise(SIGUSR1);
+#else
+ abort();
+#endif
+ return buf;
+}
+
+void *srealloc(void *oldptr, long newsize)
+{
+ void *buf;
+
+ if (!newsize) {
+ newsize = 1;
+ }
+ buf = realloc(oldptr, newsize);
+ if (!buf)
+#if !defined(USE_THREADS) || !defined(LINUX20)
+ raise(SIGUSR1);
+#else
+ abort();
+#endif
+ return buf;
+}
+
+char *sstrdup(const char *s)
+{
+ char *t = strdup(s);
+ if (!t)
+#if !defined(USE_THREADS) || !defined(LINUX20)
+ raise(SIGUSR1);
+#else
+ abort();
+#endif
+ return t;
+}
+
+/*************************************************************************/
+/*************************************************************************/
+
+/* In the future: malloc() replacements that tell us if we're leaking and
+ * maybe do sanity checks too... */
+
+/*************************************************************************/