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.
24 * @version $Id: ircd_alloc.c,v 1.10 2005/01/27 04:07:46 entrope Exp $
28 #include "ircd_alloc.h"
30 #include "ircd_string.h"
33 /* #include <assert.h> -- Now using assert in ircd_log.h */
36 static void nomem_handler(void);
38 /** Variable holding out-of-memory callback. */
39 static OutOfMemoryHandler noMemHandler
= nomem_handler
;
41 /** Default handler for out-of-memory conditions. */
48 Debug((DEBUG_FATAL
, "Out of memory, exiting"));
53 /** Set callback function for out-of-memory conditions. */
55 set_nomem_handler(OutOfMemoryHandler handler
)
57 noMemHandler
= handler
;
62 * @param[in] size Number of bytes to allocate.
63 * @param[in] x Type of allocation (ignored).
64 * @param[in] y Name of file doing allocation (ignored).
65 * @param[in] z Line number doing allocation (ignored).
66 * @return Newly allocated block of memory.
68 void* DoMalloc(size_t size
, const char* x
, const char* y
, int z
)
70 void* t
= malloc(size
);
76 /** Allocate zero-initialized memory.
77 * @param[in] size Number of bytes to allocate.
78 * @param[in] x Type of allocation (ignored).
79 * @param[in] y Name of file doing allocation (ignored).
80 * @param[in] z Line number doing allocation (ignored).
81 * @return Newly allocated block of memory.
83 void* DoMallocZero(size_t size
, const char* x
, const char* y
, int z
)
85 void* t
= malloc(size
);
92 /** Resize an allocated block of memory.
93 * @param[in] orig Original block to resize.
94 * @param[in] size Minimum size for new block.
95 * @param[in] file Name of file doing reallocation (ignored).
96 * @param[in] line Line number doing reallocation (ignored).
98 void* DoRealloc(void *orig
, size_t size
, const char *file
, int line
)
100 void* t
= realloc(orig
, size
);