From 5bc2263b54a89e28dd5092c807a86cd3c078e4d3 Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Wed, 22 May 2019 21:59:19 +0200 Subject: Add a log print function type for information reporting This type allows the use of either printf-based or log-based functions when reporting information. --- kern/printf.c | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'kern/printf.c') diff --git a/kern/printf.c b/kern/printf.c index 29267a6e..8ef3e863 100644 --- a/kern/printf.c +++ b/kern/printf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2012, 2013 Richard Braun. + * Copyright (c) 2010-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +32,20 @@ static char printf_buffer[PRINTF_BUFSIZE]; static struct spinlock printf_lock; +static int +vprintf_common(const char *format, va_list ap) +{ + int length; + + length = fmt_vsnprintf(printf_buffer, sizeof(printf_buffer), format, ap); + + for (char *ptr = printf_buffer; *ptr != '\0'; ptr++) { + console_putchar(*ptr); + } + + return length; +} + int printf(const char *format, ...) { @@ -50,16 +64,36 @@ vprintf(const char *format, va_list ap) { unsigned long flags; int length; - char *ptr; spinlock_lock_intr_save(&printf_lock, &flags); + length = vprintf_common(format, ap); + spinlock_unlock_intr_restore(&printf_lock, flags); - length = fmt_vsnprintf(printf_buffer, sizeof(printf_buffer), format, ap); + return length; +} - for (ptr = printf_buffer; *ptr != '\0'; ptr++) { - console_putchar(*ptr); - } +int +printf_ln(const char *format, ...) +{ + va_list ap; + int length; + + va_start(ap, format); + length = vprintf_ln(format, ap); + va_end(ap); + + return length; +} + +int +vprintf_ln(const char *format, va_list ap) +{ + unsigned long flags; + int length; + spinlock_lock_intr_save(&printf_lock, &flags); + length = vprintf_common(format, ap); + console_putchar('\n'); spinlock_unlock_intr_restore(&printf_lock, flags); return length; -- cgit v1.2.3