summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlain Magloire <alainm@rcsm.ee.mcgill.ca>2001-08-21 20:45:06 +0000
committerAlain Magloire <alainm@rcsm.ee.mcgill.ca>2001-08-21 20:45:06 +0000
commit5e7ea1b21253d10da7ffb6901070fd6d7b65e539 (patch)
tree10c8de5ef8162081cf533b23aef144034b66dd30 /lib
parentc1d46c30c65c89619db5f2c8939168d90d34cc01 (diff)
downloadgrep-5e7ea1b21253d10da7ffb6901070fd6d7b65e539.tar.gz
add replacement function for malloc/realloc
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am3
-rw-r--r--lib/malloc.c26
-rw-r--r--lib/realloc.c32
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);
+}