| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
* memory.h: A header for the memory functions. |
| 4 |
* |
| 5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
* USA |
| 21 |
* |
| 22 |
* $Id$ |
| 23 |
*/ |
| 24 |
|
| 25 |
LIBIO_EXTERN void (* outofmemory) (void); |
| 26 |
|
| 27 |
LIBIO_EXTERN void *MyMalloc(size_t); |
| 28 |
LIBIO_EXTERN void *MyRealloc(void *, size_t); |
| 29 |
LIBIO_EXTERN void MyFree(void *); |
| 30 |
LIBIO_EXTERN void _DupString(char **, const char *); |
| 31 |
LIBIO_EXTERN void mem_frob(void *, int); |
| 32 |
|
| 33 |
/* forte (and maybe others) don't like double declarations, |
| 34 |
* so we don't declare the inlines unless GNUC |
| 35 |
*/ |
| 36 |
#ifdef __GNUC__ |
| 37 |
LIBIO_EXTERN inline void * |
| 38 |
MyMalloc(size_t size) |
| 39 |
{ |
| 40 |
void *ret = calloc(1, size); |
| 41 |
|
| 42 |
if (ret == NULL) |
| 43 |
outofmemory(); |
| 44 |
return(ret); |
| 45 |
} |
| 46 |
|
| 47 |
LIBIO_EXTERN inline void * |
| 48 |
MyRealloc(void *x, size_t y) |
| 49 |
{ |
| 50 |
void *ret = realloc(x, y); |
| 51 |
|
| 52 |
if (ret == NULL) |
| 53 |
outofmemory(); |
| 54 |
return(ret); |
| 55 |
} |
| 56 |
|
| 57 |
LIBIO_EXTERN inline void |
| 58 |
MyFree(void *x) |
| 59 |
{ |
| 60 |
if (x != NULL) |
| 61 |
free(x); |
| 62 |
} |
| 63 |
|
| 64 |
LIBIO_EXTERN inline void |
| 65 |
_DupString(char **x, const char *y) |
| 66 |
{ |
| 67 |
(*x) = malloc(strlen(y) + 1); |
| 68 |
|
| 69 |
if (x == NULL) |
| 70 |
outofmemory(); |
| 71 |
strcpy((*x), y); |
| 72 |
} |
| 73 |
#endif /* __GNUC__ */ |
| 74 |
|
| 75 |
#define DupString(x,y) _DupString(&x, y) |