diff options
author | Ian Moffett <ian@osmora.org> | 2024-03-31 14:07:37 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-03-31 14:07:37 -0400 |
commit | d9be2d236015bf33c4edd4098da67c8241effec5 (patch) | |
tree | 4d183ab970574e9341327471720f1ae832366eea /sys/kern/kern_syslog.c | |
parent | 2f20af692b14a59c01156d228b1aec1bc38a140d (diff) |
kernel: syslog: Cleanup logging routines
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/kern/kern_syslog.c')
-rw-r--r-- | sys/kern/kern_syslog.c | 63 |
1 files changed, 4 insertions, 59 deletions
diff --git a/sys/kern/kern_syslog.c b/sys/kern/kern_syslog.c index cdce157..c30f31a 100644 --- a/sys/kern/kern_syslog.c +++ b/sys/kern/kern_syslog.c @@ -48,68 +48,13 @@ syslog_write(const char *s, size_t len) } } -/* - * TODO: Replace with vsnprintf() - */ -static void -syslog_handle_fmt(va_list *ap, char fmt_spec) -{ - char tmp_ch; - int64_t tmp_int; - const char *tmp_str; - char tmp_buf[256] = { 0 }; - - size_t tmp_len; - - switch (fmt_spec) { - case 'c': - tmp_ch = va_arg(*ap, int); - syslog_write(&tmp_ch, 1); - break; - case 's': - tmp_str = va_arg(*ap, const char *); - syslog_write(tmp_str, strlen(tmp_str)); - break; - case 'd': - tmp_int = va_arg(*ap, int64_t); - itoa(tmp_int, tmp_buf, 10); - syslog_write(tmp_buf, strlen(tmp_buf)); - break; - case 'p': - tmp_int = va_arg(*ap, uint64_t); - itoa(tmp_int, tmp_buf, 16); - tmp_len = strlen(tmp_buf); - /* - * Now we pad this. - * - * XXX TODO: This assumes 64-bits, should be - * cleaned up. - */ - for (size_t i = 0; i < 18 - tmp_len; ++i) { - syslog_write("0", 1); - } - syslog_write(tmp_buf + 2, tmp_len - 2); - break; - case 'x': - tmp_int = va_arg(*ap, uint64_t); - itoa(tmp_int, tmp_buf, 16); - tmp_len = strlen(tmp_buf); - syslog_write(tmp_buf + 2, tmp_len - 2); - break; - } -} - void vkprintf(const char *fmt, va_list *ap) { - while (*fmt) { - if (*fmt == '%') { - ++fmt; - syslog_handle_fmt(ap, *fmt++); - } else { - syslog_write(fmt++, 1); - } - } + char buffer[1024] = {0}; + + vsnprintf(buffer, sizeof(buffer), fmt, *ap); + syslog_write(buffer, strlen(buffer)); } void |