summaryrefslogtreecommitdiff
path: root/kern/printf.c
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2019-05-22 21:59:19 +0200
committerRichard Braun <rbraun@sceen.net>2019-05-22 21:59:19 +0200
commit5bc2263b54a89e28dd5092c807a86cd3c078e4d3 (patch)
treead399e98a6d46bad25543a4f8680335f3abb1bf8 /kern/printf.c
parentc45d94a590d778c26dc78386c41231fed9df1b14 (diff)
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.
Diffstat (limited to 'kern/printf.c')
-rw-r--r--kern/printf.c46
1 files changed, 40 insertions, 6 deletions
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;