[Concept,06/13] sandbox: Add support for length-based console output
Commit Message
From: Simon Glass <simon.glass@canonical.com>
Add os_putsn() to support length-based output in sandbox environments.
This allows putsn() to work correctly before the serial console is
initialised.
The implementation uses os_write() directly for efficiency, and os_puts()
is refactored to use os_putsn() to reduce code duplication.
Note this changes sandbox to write all characters in one call.
Co-developed-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
arch/sandbox/cpu/os.c | 8 ++++++--
include/os.h | 13 +++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
@@ -827,10 +827,14 @@ void os_putc(int ch)
os_write(1, &ch, 1);
}
+void os_putsn(const char *str, int len)
+{
+ os_write(1, str, len);
+}
+
void os_puts(const char *str)
{
- while (*str)
- os_putc(*str++);
+ os_putsn(str, strlen(str));
}
void os_flush(void)
@@ -385,6 +385,19 @@ void os_putc(int ch);
*/
void os_puts(const char *str);
+/**
+ * os_putsn() - write a string with length to controlling OS terminal
+ *
+ * This bypasses the U-Boot console support and writes directly to the OS
+ * stdout file descriptor.
+ *
+ * Outputs exactly @len characters from @str, regardless of any nul characters.
+ *
+ * @str: String to write (need not be nul-terminated)
+ * @len: Number of characters to write
+ */
+void os_putsn(const char *str, int len);
+
/**
* os_flush() - flush controlling OS terminal
*