Nucleus
Barry Library printf 366395f (3 years, 2 months ago)
diff --git a/include/nucleus/panic.h b/include/nucleus/panic.h
index 63034cf..27eea94 100644
--- a/include/nucleus/panic.h
+++ b/include/nucleus/panic.h
@@ -1,6 +1,7 @@
#ifndef _NUCLEUS_PANIC_H
#define _NUCLEUS_PANIC_H
+int sprintf(char *buf, char *fmt, ...);
void kprintf(char *fmt, ...);
_Noreturn void panic(char *fmt, ...);
diff --git a/kernel/panic.c b/lib/printf.c
similarity index 91%
rename from kernel/panic.c
rename to lib/printf.c
index 5d1a847..de1a729 100644
--- a/kernel/panic.c
+++ b/lib/printf.c
@@ -1,8 +1,8 @@
/*
- * This file implements the full kernel panic routine. This routine does not
- * return, and is essentially a shutdown routine. It will print a message to
- * the debug port and halt the processor. In an ideal build, this function
- * won't need to be linked in.
+ * This file implements the *printf routines, as well as the full kernel panic
+ * routine. The kernel panic routine does not return, and halts the processor
+ * after running, the other *printf routines work as they normally would.
+ * kprintf() outputs to the debug port rather than to the screen.
*/
#include <stdint.h>
@@ -246,6 +246,18 @@ repeat:
return str-buf;
}
+/* Format a string into a buffer */
+int
+sprintf(char *buf, char *fmt, ...)
+{
+ int ret;
+ va_list args;
+ va_start(args, fmt);
+ ret = vsprintf(buf, fmt, args);
+ va_end(args);
+ return ret;
+}
+
/* Print formatted text to debug port */
void
kprintf(char *fmt, ...)