[Concept,03/13] console: Add length-based console-recording support

Message ID 20260204001002.2638622-4-sjg@u-boot.org
State New
Headers
Series Add putsn() for length-based console output |

Commit Message

Simon Glass Feb. 4, 2026, 12:09 a.m. UTC
  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(-)
  

Patch

diff --git a/common/console.c b/common/console.c
index 6ce2c4d361d..581c383ce5e 100644
--- a/common/console.c
+++ b/common/console.c
@@ -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)
 {
 }