1 /************************************************************************
2 * IRC - Internet Relay Chat, ircd/ircd_alloc.c
3 * Copyright (C) 1999 Thomas Helvey (BleepSoft)
5 * See file AUTHORS in IRC package for additional names of
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 1, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * @brief IRC daemon memory allocation functions.
28 #include "ircd_alloc.h"
29 #include "ircd_string.h"
35 static void nomem_handler(void);
37 /** Variable holding out-of-memory callback. */
38 static OutOfMemoryHandler noMemHandler = nomem_handler;
40 /** Default handler for out-of-memory conditions. */
47 Debug((DEBUG_FATAL, "Out of memory, exiting"));
52 /** Set callback function for out-of-memory conditions. */
54 set_nomem_handler(OutOfMemoryHandler handler)
56 noMemHandler = handler;
60 * @param[in] size Number of bytes to allocate.
61 * @param[in] x Type of allocation (ignored).
62 * @param[in] y Name of file doing allocation (ignored).
63 * @param[in] z Line number doing allocation (ignored).
64 * @return Newly allocated block of memory.
66 void* DoMalloc(size_t size, const char* x, const char* y, int z)
68 void* t = malloc(size);
74 /** Allocate zero-initialized memory.
75 * @param[in] size Number of bytes to allocate.
76 * @param[in] x Type of allocation (ignored).
77 * @param[in] y Name of file doing allocation (ignored).
78 * @param[in] z Line number doing allocation (ignored).
79 * @return Newly allocated block of memory.
81 void* DoMallocZero(size_t size, const char* x, const char* y, int z)
83 void* t = malloc(size);
90 /** Resize an allocated block of memory.
91 * @param[in] orig Original block to resize.
92 * @param[in] size Minimum size for new block.
93 * @param[in] file Name of file doing reallocation (ignored).
94 * @param[in] line Line number doing reallocation (ignored).
96 void* DoRealloc(void *orig, size_t size, const char *file, int line)
98 void* t = realloc(orig, size);