From 98dc2fbedf18ef1ae071afe718ed5133731ea248 Mon Sep 17 00:00:00 2001 From: hadaq Date: Thu, 25 Jul 2002 09:25:13 +0000 Subject: [PATCH] Initial revision --- compat/Makefile | 29 ++++++++++++++++++++++++++ compat/examples/Makefile | 21 +++++++++++++++++++ compat/examples/testsyslog.c | 12 +++++++++++ compat/libgen.h | 4 ++++ compat/stdint.h | 12 +++++++++++ compat/syslog.c | 40 ++++++++++++++++++++++++++++++++++++ compat/syslog.h | 23 +++++++++++++++++++++ 7 files changed, 141 insertions(+) create mode 100644 compat/Makefile create mode 100644 compat/examples/Makefile create mode 100644 compat/examples/testsyslog.c create mode 100644 compat/libgen.h create mode 100644 compat/stdint.h create mode 100644 compat/syslog.c create mode 100644 compat/syslog.h diff --git a/compat/Makefile b/compat/Makefile new file mode 100644 index 0000000..e50905b --- /dev/null +++ b/compat/Makefile @@ -0,0 +1,29 @@ +# CC = c89 +CC = gcc -ansi -g + +ARFLAGS = rv + +DESTDIR = $(HOME) +# DESTDIR = /usr/local + +# LIBCOMPATINCS = +# LIBCOMPATOBJS = + +LIBCOMPATINCS = syslog.h stdint.h libgen.h +LIBCOMPATOBJS = libcompat.a(syslog.o) + +all: libcompat.a + +libcompat.a: $(LIBCOMPATOBJS) +# $(AR) $(ARFLAGS) $@ $? + +syslog.o: syslog.c syslog.h + +install: $(LIBCOMPATINCS) + -mkdir $(DESTDIR)/include + cp $(LIBCOMPATINCS) $(DESTDIR)/include + -mkdir $(DESTDIR)/lib/$(SYSTYPE) + cp libcompat.a $(DESTDIR)/lib/$(SYSTYPE) + +clean: + rm -f *.o *.a diff --git a/compat/examples/Makefile b/compat/examples/Makefile new file mode 100644 index 0000000..9dbbacd --- /dev/null +++ b/compat/examples/Makefile @@ -0,0 +1,21 @@ +# CC = c89 +CC = gcc -ansi + +INCDIR = ../ +LIBDIR = ../ + +CFLAGS = -g -I$(INCDIR) -DLOG_PERROR_DOESNT_WORK +LOADLIBES = -L$(LIBDIR) -lcompat -lnetinet + +all: testsyslog + +testsyslog: testsyslog.o + $(CC) $(CFLAGS) $(LDFLAGS) testsyslog.o $(LOADLIBES) -o testsyslog + +clean: + rm -f *.o + +depend: + gcc -MM $(CFLAGS) *.c + +testsyslog.o: testsyslog.c diff --git a/compat/examples/testsyslog.c b/compat/examples/testsyslog.c new file mode 100644 index 0000000..a223522 --- /dev/null +++ b/compat/examples/testsyslog.c @@ -0,0 +1,12 @@ +#include + +int main(int argc, char *argv[]) { + openlog(argv[0], LOG_PERROR, LOG_LOCAL0); + setlogmask(LOG_UPTO(LOG_INFO)); + syslog(LOG_INFO, "Hello, World!"); + syslog(LOG_INFO, "%d, %d, %d, %s", 1, 2, 3, "viele"); + syslog(LOG_DEBUG, "This is a debug message"); + closelog(); + + return 0; +} diff --git a/compat/libgen.h b/compat/libgen.h new file mode 100644 index 0000000..faed44f --- /dev/null +++ b/compat/libgen.h @@ -0,0 +1,4 @@ +#ifndef OUR_LIBGEN_H +#define OUR_LIBGEN_H + +#endif diff --git a/compat/stdint.h b/compat/stdint.h new file mode 100644 index 0000000..e75ff6f --- /dev/null +++ b/compat/stdint.h @@ -0,0 +1,12 @@ +#ifndef OUR_STDINT_H +#define OUR_STDINT_H + +typedef signed char int8_t; +typedef short int int16_t; +typedef int int32_t; + +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; + +#endif diff --git a/compat/syslog.c b/compat/syslog.c new file mode 100644 index 0000000..58eb62f --- /dev/null +++ b/compat/syslog.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +#define OUR_IDENT_LEN 256 + +static unsigned ourMaskpri = 0xffffffff; +static unsigned ourLogopt = 0; +static char ourIdent[OUR_IDENT_LEN] = ""; + +void SYSLOG_syslog(int priority, const char *message, ...) { + va_list ap; + if ((ourLogopt & LOG_PERROR) && (ourMaskpri & (1 << priority))) { + fprintf(stderr, "%s: ", ourIdent); + va_start(ap, message); + vfprintf(stderr, message, ap); + va_end(ap); + fprintf(stderr, "%c", '\n'); + } + + va_start(ap, message); + vsyslog(priority, message, ap); + va_end(ap); +} + +void SYSLOG_openlog(const char *ident, int logopt, int facility) { + strncpy(ourIdent, ident, OUR_IDENT_LEN-1); + ourLogopt = logopt; + openlog(ident, logopt, facility); +} + +void SYSLOG_closelog(void) { + closelog(); +} + +int SYSLOG_setlogmask(int maskpri) { + ourMaskpri = maskpri; + return setlogmask(maskpri); +} diff --git a/compat/syslog.h b/compat/syslog.h new file mode 100644 index 0000000..e70baf6 --- /dev/null +++ b/compat/syslog.h @@ -0,0 +1,23 @@ +#ifndef OUR_SYSLOG_H +#define OUR_SYSLOG_H + +#include + +#if !defined(LOG_PERROR) || defined(LOG_PERROR_DOESNT_WORK) + +#if !defined(LOG_PERROR) +#define LOG_PERROR 0x20 /* log to stderr as well */ +#endif + +void SYSLOG_openlog(const char *ident, int logopt, int facility); +void SYSLOG_syslog(int priority, const char *message, ...); +void SYSLOG_closelog(); +int SYSLOG_setlogmask(int maskpri); + +#define syslog SYSLOG_syslog +#define openlog SYSLOG_openlog +#define closelog SYSLOG_closelog +#define setlogmask SYSLOG_setlogmask + +#endif +#endif -- 2.43.0