diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 4 | ||||
-rw-r--r-- | lib/lib.c | 7 | ||||
-rwxr-xr-x | lib/malloc.c | 17 | ||||
-rw-r--r-- | lib/realloc.c | 27 |
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; +} |