sandbox: add function os_printf()
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Mon, 4 Apr 2022 20:45:03 +0000 (22:45 +0200)
committerSimon Glass <sjg@chromium.org>
Tue, 28 Jun 2022 02:09:51 +0000 (03:09 +0100)
Before setting up the devices U-Boot's printf() function cannot be used
for console output. Provide function os_printf() to print to stderr.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
arch/sandbox/cpu/os.c
include/os.h

index 3b23060..f937991 100644 (file)
@@ -12,6 +12,7 @@
 #include <getopt.h>
 #include <setjmp.h>
 #include <signal.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -54,6 +55,18 @@ ssize_t os_write(int fd, const void *buf, size_t count)
        return write(fd, buf, count);
 }
 
+int os_printf(const char *fmt, ...)
+{
+       va_list args;
+       int i;
+
+       va_start(args, fmt);
+       i = vfprintf(stdout, fmt, args);
+       va_end(args);
+
+       return i;
+}
+
 off_t os_lseek(int fd, off_t offset, int whence)
 {
        if (whence == OS_SEEK_SET)
index 10e198c..1481787 100644 (file)
@@ -17,6 +17,13 @@ struct rtc_time;
 struct sandbox_state;
 
 /**
+ * os_printf() - print directly to OS console
+ *
+ * @format: format string
+ */
+int os_printf(const char *format, ...);
+
+/**
  * Access to the OS read() system call
  *
  * @fd:                File descriptor as returned by os_open()