From d0fec7a322f6fcfa4ab0fe1a7de62cc86c1b8c4c Mon Sep 17 00:00:00 2001 From: hpa Date: Fri, 30 Mar 2001 01:02:55 +0000 Subject: [PATCH] Add replacement library files --- lib/Makefile | 23 +++++++++++++++++++++++ lib/bsdsignal.c | 21 +++++++++++++++++++++ lib/xmalloc.c | 21 +++++++++++++++++++++ lib/xstrdup.c | 22 ++++++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 lib/Makefile create mode 100644 lib/bsdsignal.c create mode 100644 lib/xmalloc.c create mode 100644 lib/xstrdup.c diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 0000000..fb56fa7 --- /dev/null +++ b/lib/Makefile @@ -0,0 +1,23 @@ +# +# Extra functions which may not be available everywhere +# + +include ../MCONFIG +include ../MRULES + +all: libxtra.a + +install: + +clean: + -rm -f *.a *.o + +spotless: clean + -rm -f *~ + +libxtra.a: $(LIBOBJS) + -rm -f libxtra.a + $(AR) libxtra.a $(LIBOBJS) + $(RANLIB) libxtra.a + + diff --git a/lib/bsdsignal.c b/lib/bsdsignal.c new file mode 100644 index 0000000..7740740 --- /dev/null +++ b/lib/bsdsignal.c @@ -0,0 +1,21 @@ +/* + * bsdsignal.c + * + * Use sigaction() to simulate BSD signal() + */ + +#include +#include +#include + +void bsd_signal(int signum, void (*handler)(int)) +{ + struct sigaction action; + + memset(&action, 0, sizeof action); + action.sa_handler = handler; + sigemptyset(&action.sa_mask); + action.sa_flags = SA_RESTART; + + sigaction(hander, action, NULL); +} diff --git a/lib/xmalloc.c b/lib/xmalloc.c new file mode 100644 index 0000000..6e8ae24 --- /dev/null +++ b/lib/xmalloc.c @@ -0,0 +1,21 @@ +/* + * xmalloc.c + * + * Simple error-checking version of malloc() + * + */ + +#include +#include + +void *xmalloc(size_t size) +{ + void *p = malloc(size); + + if ( !p ) { + fprintf(stderr, "Out of memory!\n"); + exit(128); + } + + return p; +} diff --git a/lib/xstrdup.c b/lib/xstrdup.c new file mode 100644 index 0000000..5d65b7e --- /dev/null +++ b/lib/xstrdup.c @@ -0,0 +1,22 @@ +/* + * xstrdup.c + * + * Simple error-checking version of strdup() + * + */ + +#include +#include +#include + +char *xstrdup(const char *s) +{ + char *p = strdup(s); + + if ( !p ) { + fprintf(stderr, "Out of memory!\n"); + exit(128); + } + + return p; +}