/************************************************************************
- * IRC - Internet Relay Chat, src/ircd_log.c
+ * IRC - Internet Relay Chat, ircd/ircd_alloc.c
* Copyright (C) 1999 Thomas Helvey (BleepSoft)
*
* See file AUTHORS in IRC package for additional names of
*
* $Id$
*/
+#include "config.h"
+
#include "ircd_alloc.h"
#include "ircd_string.h"
#include "s_debug.h"
#include <assert.h>
+#include <string.h>
-#if defined(NDEBUG)
-/*
- * RELEASE: allocation functions
- */
+static void nomem_handler(void);
+
+/* Those ugly globals... */
+OutOfMemoryHandler noMemHandler = nomem_handler;
+void *malloc_tmp;
-static void nomem_handler(void)
+static void
+nomem_handler(void)
{
+#ifdef MDEBUG
+ assert(0);
+#else
Debug((DEBUG_FATAL, "Out of memory, exiting"));
exit(2);
+#endif
}
-static OutOfMemoryHandler noMemHandler = nomem_handler;
-
-void set_nomem_handler(OutOfMemoryHandler handler)
+void
+set_nomem_handler(OutOfMemoryHandler handler)
{
noMemHandler = handler;
}
-void* MyMalloc(size_t size)
+void* DoMalloc(size_t size, const char* x, const char* y, int z)
{
- void* p = malloc(size);
- if (!p)
+ void* t = malloc(size);
+ if (!t)
(*noMemHandler)();
- return p;
+ return t;
}
-void* MyRealloc(void* p, size_t size)
+void* DoMallocZero(size_t size, const char* x, const char* y, int z)
{
- void* x = realloc(p, size);
- if (!x)
+ void* t = malloc(size);
+ if (!t)
(*noMemHandler)();
- return x;
+ memset(t, 0, size);
+ return t;
}
-void* MyCalloc(size_t nelem, size_t size)
+void* DoRealloc(void *orig, size_t size, const char *file, int line)
{
- void* p = calloc(nelem, size);
- if (!p)
+ void* t = realloc(orig, size);
+ if (!t)
(*noMemHandler)();
- return p;
-}
-
-#else /* !defined(NDEBUG) */
-/*
- * DEBUG: allocation functions
- */
-void set_nomem_handler(OutOfMemoryHandler handler)
-{
- assert(0 != handler);
- fda_set_nomem_handler(handler);
+ return t;
}
-
-#endif /* !defined(NDEBUG) */
-