diff options
author | Tom Rini <trini@konsulko.com> | 2025-04-03 16:54:59 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2025-04-03 16:54:59 -0600 |
commit | 1aa8b03c01f72cefee31039571f2de2f4ccfe0eb (patch) | |
tree | 06e5b9076311df8043ff67124427c1dee11e952c /common/console.c | |
parent | 1f2a3d066c99f57675162ce09586e9de30407f1b (diff) | |
parent | da8694a7d2cc9fdfd67e8a039ba1e70bdd543d0b (diff) |
Merge patch series "membuff: Add tests and update to support a flag for empty/full"
Simon Glass <sjg@chromium.org> says:
The membuff implementation curently has no tests. It also assumes that
head and tail can never correspond unless the buffer is empty.
This series provides a compile-time flag to support a 'full' flag. It
also adds some tests of the main routines.
The data structure is also renamed to membuf which fits better with
U-Boot.
There may be some cases in the code which could be optimised a little,
but the implementation is functional.
Link: https://lore.kernel.org/r/20250318152059.1464369-1-sjg@chromium.org
Diffstat (limited to 'common/console.c')
-rw-r--r-- | common/console.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/common/console.c b/common/console.c index 26812b2ccbe..b69bb189639 100644 --- a/common/console.c +++ b/common/console.c @@ -101,7 +101,7 @@ static void console_record_putc(const char c) if (!(gd->flags & GD_FLG_RECORD)) return; if (gd->console_out.start && - !membuff_putbyte((struct membuff *)&gd->console_out, c)) + !membuf_putbyte((struct membuf *)&gd->console_out, c)) gd->flags |= GD_FLG_RECORD_OVF; } @@ -112,7 +112,7 @@ static void console_record_puts(const char *s) if (gd->console_out.start) { int len = strlen(s); - if (membuff_put((struct membuff *)&gd->console_out, s, len) != + if (membuf_put((struct membuf *)&gd->console_out, s, len) != len) gd->flags |= GD_FLG_RECORD_OVF; } @@ -125,7 +125,7 @@ static int console_record_getc(void) if (!gd->console_in.start) return -1; - return membuff_getbyte((struct membuff *)&gd->console_in); + return membuf_getbyte((struct membuf *)&gd->console_in); } static int console_record_tstc(void) @@ -133,7 +133,7 @@ static int console_record_tstc(void) if (!(gd->flags & GD_FLG_RECORD)) return 0; if (gd->console_in.start) { - if (membuff_peekbyte((struct membuff *)&gd->console_in) != -1) + if (membuf_peekbyte((struct membuf *)&gd->console_in) != -1) return 1; } return 0; @@ -810,14 +810,14 @@ int console_record_init(void) { int ret; - ret = membuff_new((struct membuff *)&gd->console_out, - gd->flags & GD_FLG_RELOC ? - CONFIG_CONSOLE_RECORD_OUT_SIZE : - CONFIG_CONSOLE_RECORD_OUT_SIZE_F); + ret = membuf_new((struct membuf *)&gd->console_out, + gd->flags & GD_FLG_RELOC ? + CONFIG_CONSOLE_RECORD_OUT_SIZE : + CONFIG_CONSOLE_RECORD_OUT_SIZE_F); if (ret) return ret; - ret = membuff_new((struct membuff *)&gd->console_in, - CONFIG_CONSOLE_RECORD_IN_SIZE); + ret = membuf_new((struct membuf *)&gd->console_in, + CONFIG_CONSOLE_RECORD_IN_SIZE); /* Start recording from the beginning */ gd->flags |= GD_FLG_RECORD; @@ -827,8 +827,8 @@ int console_record_init(void) void console_record_reset(void) { - membuff_purge((struct membuff *)&gd->console_out); - membuff_purge((struct membuff *)&gd->console_in); + membuf_purge((struct membuf *)&gd->console_out); + membuf_purge((struct membuf *)&gd->console_in); gd->flags &= ~GD_FLG_RECORD_OVF; } @@ -847,23 +847,23 @@ int console_record_readline(char *str, int maxlen) if (console_record_isempty()) return -ENOENT; - return membuff_readline((struct membuff *)&gd->console_out, str, + return membuf_readline((struct membuf *)&gd->console_out, str, maxlen, '\0', false); } int console_record_avail(void) { - return membuff_avail((struct membuff *)&gd->console_out); + return membuf_avail((struct membuf *)&gd->console_out); } bool console_record_isempty(void) { - return membuff_isempty((struct membuff *)&gd->console_out); + return membuf_isempty((struct membuf *)&gd->console_out); } int console_in_puts(const char *str) { - return membuff_put((struct membuff *)&gd->console_in, str, strlen(str)); + return membuf_put((struct membuf *)&gd->console_in, str, strlen(str)); } #endif |