From 2c8fdd7aea1d3c6c380ea5b5080147dc7fe9c38f Mon Sep 17 00:00:00 2001 From: Gregor Herburger Date: Mon, 13 Apr 2026 17:24:53 +0200 Subject: console: add console_flush_stdin() Add a common helper console_flush_stdin() to drain all pending characters from stdin. This consolidates the open-coded while (tstc()) getchar() pattern that appeared in multiple places across the tree. Signed-off-by: Gregor Herburger Reviewed-by: Alexander Sverdlin Reviewed-by: Quentin Schulz Reviewed-by: Simon Glass --- cmd/conitrace.c | 4 ++-- cmd/eficonfig.c | 6 +++--- cmd/eficonfig_sbkey.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'cmd') diff --git a/cmd/conitrace.c b/cmd/conitrace.c index 6cc113328eb..aef094e03df 100644 --- a/cmd/conitrace.c +++ b/cmd/conitrace.c @@ -6,6 +6,7 @@ * Copyright (c) 2018, Heinrich Schuchardt */ #include +#include #include static int do_conitrace(struct cmd_tbl *cmdtp, int flag, int argc, @@ -17,8 +18,7 @@ static int do_conitrace(struct cmd_tbl *cmdtp, int flag, int argc, printf("To terminate type 'x'\n"); /* Empty input buffer */ - while (tstc()) - getchar(); + console_flush_stdin(); for (;;) { int c = getchar(); diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index d8d946c87ac..60c39bc3a99 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -6,8 +6,9 @@ */ #include -#include #include +#include +#include #include #include #include @@ -167,8 +168,7 @@ static void eficonfig_menu_adjust(struct efimenu *efi_menu, bool add) void eficonfig_print_msg(char *msg) { /* Flush input */ - while (tstc()) - getchar(); + console_flush_stdin(); printf(ANSI_CURSOR_HIDE ANSI_CLEAR_CONSOLE diff --git a/cmd/eficonfig_sbkey.c b/cmd/eficonfig_sbkey.c index b3325a540f9..a6c5416d3a5 100644 --- a/cmd/eficonfig_sbkey.c +++ b/cmd/eficonfig_sbkey.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -288,8 +289,7 @@ static efi_status_t eficonfig_process_show_siglist(void *data) } } - while (tstc()) - getchar(); + console_flush_stdin(); printf("\n\n Press any key to continue"); getchar(); -- cgit v1.2.3