diff options
Diffstat (limited to 'io')
-rw-r--r-- | io/interrupt.h | 6 | ||||
-rw-r--r-- | io/log.c | 68 | ||||
-rw-r--r-- | io/log.d | 1 | ||||
-rw-r--r-- | io/log.h | 22 |
4 files changed, 97 insertions, 0 deletions
diff --git a/io/interrupt.h b/io/interrupt.h new file mode 100644 index 0000000..444ff01 --- /dev/null +++ b/io/interrupt.h @@ -0,0 +1,6 @@ +#ifndef JOVE_IO_INTERRUPT_H +#define JOVE_IO_INTERRUPT_H 1 + + + +#endif diff --git a/io/log.c b/io/log.c new file mode 100644 index 0000000..14397a7 --- /dev/null +++ b/io/log.c @@ -0,0 +1,68 @@ +#include "log.h" +#include "lib/jove.h" +#include "lib/string.h" +#include "lib/format.h" + +static struct LogDevice *s_first_logdev = NULL; + +void +klog_newdev(struct LogDevice *dev) +{ + if(s_first_logdev == NULL) { + s_first_logdev = dev; + }else{ + dev->chain = s_first_logdev; + s_first_logdev = dev; + } +} + +static void +s_klogc(struct LogDevice *dev, char c) +{ + dev->out(&c, 1); + if(dev->chain != NULL) + s_klogc(dev->chain, c); +} + +void +klogc(char c) +{ + s_klogc(s_first_logdev, c); +} + +static void +s_klogs(struct LogDevice *dev, const char *s, size_t slen) +{ + dev->out(s, slen); + if(dev->chain != NULL) + s_klogs(dev->chain, s, slen); +} + +void +klogs(const char *s) +{ + size_t slen = strlen(s); + s_klogs(s_first_logdev, s, slen); +} + +void +klogsn(const char *s, size_t len) +{ + s_klogs(s_first_logdev, s, len); +} + +void +kvlogf(const char *fmt, va_list ap) +{ + char buffer[256]; + svfmt(buffer, 256, fmt, ap); + klogs(buffer); +} + +void klogf(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + kvlogf(fmt, ap); + va_end(ap); +} diff --git a/io/log.d b/io/log.d new file mode 100644 index 0000000..b8609ce --- /dev/null +++ b/io/log.d @@ -0,0 +1 @@ +io/log.o: io/log.c io/log.h lib/jove.h lib/string.h lib/format.h diff --git a/io/log.h b/io/log.h new file mode 100644 index 0000000..ad1526d --- /dev/null +++ b/io/log.h @@ -0,0 +1,22 @@ +#ifndef JOVE_IO_LOG_H +#define JOVE_IO_LOG_H 1 + +#include <stddef.h> + +struct LogDevice +{ + void (*out)(const char*, size_t); + struct LogDevice *chain; +}; + +void klog_newdev(struct LogDevice *dev); + +void klogc(char c); +void klogs(const char *s); +void klogsn(const char *s, size_t len); + +#include <stdarg.h> +void kvlogf(const char *fmt, va_list ap); +void klogf(const char *fmt, ...); + +#endif |