[Concept,03/13] console: Add length-based console-recording support
Commit Message
From: Simon Glass <simon.glass@canonical.com>
Console recording uses membuf_put() which already supports length-based
writes. Add console_record_putsn() to accept a length parameter directly
instead of calling strlen() internally.
Refactor console_record_puts() to use console_record_putsn() to reduce
code duplication. Since console recording is a size-increasing feature
for testing, this refactoring is appropriate.
This provides the foundation for a public putsn() API that can output
strings without requiring nul-termination.
Co-developed-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
common/console.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
@@ -43,12 +43,11 @@ static void console_record_putc(const char c)
}
}
-static void console_record_puts(const char *s)
+static void console_record_putsn(const char *s, int len)
{
if (!(gd->flags & GD_FLG_RECORD))
return;
if (gd->console_out.start) {
- int len = strlen(s);
int written;
written = membuf_put((struct membuf *)&gd->console_out, s, len);
@@ -59,6 +58,11 @@ static void console_record_puts(const char *s)
}
}
+static void console_record_puts(const char *s)
+{
+ console_record_putsn(s, strlen(s));
+}
+
static int console_record_getc(void)
{
if (!(gd->flags & GD_FLG_RECORD))
@@ -84,6 +88,10 @@ static void console_record_putc(char c)
{
}
+static void __maybe_unused console_record_putsn(const char *s, int len)
+{
+}
+
static void console_record_puts(const char *s)
{
}