diff options
-rw-r--r-- | lib/Makefile.am | 3 | ||||
-rw-r--r-- | lib/malloc.c | 26 | ||||
-rw-r--r-- | lib/realloc.c | 32 |
3 files changed, 59 insertions, 2 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index fb5985aa..6d8cf647 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -18,5 +18,4 @@ noinst_HEADERS = \ closeout.h error.h exclude.h fnmatch.h getopt.h \ hard-locale.h obstack.h quotearg.h regex.h savedir.h xalloc.h xstrtol.h -EXTRA_DIST = strtol.c - +EXTRA_DIST = strtol.c malloc.c realloc.c diff --git a/lib/malloc.c b/lib/malloc.c new file mode 100644 index 00000000..1d198709 --- /dev/null +++ b/lib/malloc.c @@ -0,0 +1,26 @@ +/* rpl_malloc.c -- a replacement for malloc that don't accept 0 size + Copyright (C) 2001 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#include <stdlib.h> + +void * +rpl_malloc(size_t size) +{ + if (!size) + size++; + return malloc(size); +} diff --git a/lib/realloc.c b/lib/realloc.c new file mode 100644 index 00000000..2eef59ca --- /dev/null +++ b/lib/realloc.c @@ -0,0 +1,32 @@ +/* rpl_realloc.c -- a replacement for broken realloc implementations + Copyright (C) 2001 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#include <stdlib.h> + +void * +rpl_realloc(void *ptr, size_t size) +{ + if (!ptr) + return malloc(size); + if (!size) + { + if (ptr) + free(ptr); + return malloc(size); + } + return realloc(ptr, size); +} |