summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWill Estes <wlestes@users.sourceforge.net>2012-03-21 18:36:28 +0000
committerWill Estes <wlestes@users.sourceforge.net>2012-03-21 18:36:28 +0000
commit83f0c4cac94bfaab45ae5d1c227d0af30b5ff9bf (patch)
tree6cf9cb937b7aca96417bc2cb16a50d454c979342 /lib
parent0b1924073865a1124ba0d4813fc701653d6eb424 (diff)
provide malloc() and realloc() for systems that do not have satisfactory versions; resolves #1899047
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am4
-rw-r--r--lib/lib.c7
-rwxr-xr-xlib/malloc.c17
-rw-r--r--lib/realloc.c27
4 files changed, 55 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644
index 0000000..53b4d48
--- /dev/null
+++ b/lib/Makefile.am
@@ -0,0 +1,4 @@
+noinst_LIBRARIES = libcompat.a
+libcompat_a_SOURCES = lib.c
+libcompat_a_LIBADD = $(LIBOBJS)
+
diff --git a/lib/lib.c b/lib/lib.c
new file mode 100644
index 0000000..a8ff70f
--- /dev/null
+++ b/lib/lib.c
@@ -0,0 +1,7 @@
+/* Since building an empty library could cause problems, we provide a
+ * function to go into the library. We could make this non-trivial by
+ * moving something that flex treats as a library function into this
+ * directory. */
+
+void do_nothing(){ return;}
+
diff --git a/lib/malloc.c b/lib/malloc.c
new file mode 100755
index 0000000..d4c605f
--- /dev/null
+++ b/lib/malloc.c
@@ -0,0 +1,17 @@
+ #include <config.h>
+ #undef malloc
+
+ #include <sys/types.h>
+
+ void *malloc ();
+
+ /* Allocate an N-byte block of memory from the heap.
+ If N is zero, allocate a 1-byte block. */
+
+ void *
+ rpl_malloc (size_t n)
+ {
+ if (n == 0)
+ n = 1;
+ return malloc (n);
+ }
diff --git a/lib/realloc.c b/lib/realloc.c
new file mode 100644
index 0000000..d7bb629
--- /dev/null
+++ b/lib/realloc.c
@@ -0,0 +1,27 @@
+#include <config.h>
+
+#include <stdlib.h>
+
+#include <errno.h>
+
+void * rpl_realloc (void *p, size_t n)
+{
+ void *result;
+
+ if (n == 0)
+ {
+ n = 1;
+ }
+
+ if (p == NULL)
+ {
+ result = malloc (n);
+ }
+ else
+ result = realloc (p, n);
+
+ if (result == NULL)
+ errno = ENOMEM;
+
+ return result;
+}