[PATCH 4/5] console: give each console implementation its own console_ctrlc()
Ahmad Fatoum
a.fatoum at barebox.org
Sun Nov 8 01:32:06 PST 2026
ctrlc_non_interruptible() reads the console input itself, inside an
ifdef for the architectures that bring their own check. Have the full
and the simple console each provide a console_ctrlc() for it instead,
so that they can check differently, and test CONFIG_ARCH_HAS_CTRLC with
IS_ENABLED().
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
common/console.c | 10 ++++++++++
common/console_ctrlc.c | 10 ++++------
common/console_simple.c | 10 ++++++++++
include/console.h | 4 ++--
4 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/common/console.c b/common/console.c
index 0722af0a40fc..c57bb87b0114 100644
--- a/common/console.c
+++ b/common/console.c
@@ -605,6 +605,16 @@ int pollchar(ktime_t duration)
}
EXPORT_SYMBOL(pollchar);
+/**
+ * console_ctrlc - check the console input for a Ctrl-C
+ *
+ * Return: true if Ctrl-C was pressed
+ */
+bool console_ctrlc(void)
+{
+ return tstc() && getchar() == 3;
+}
+
int console_putc(struct console_device *con, char c)
{
bool crlf = c == '\n';
diff --git a/common/console_ctrlc.c b/common/console_ctrlc.c
index 6fbe07252eff..5c912841c694 100644
--- a/common/console_ctrlc.c
+++ b/common/console_ctrlc.c
@@ -28,12 +28,10 @@ int ctrlc_non_interruptible(void)
if (ctrlc_abort)
return 1;
-#ifdef CONFIG_ARCH_HAS_CTRLC
- ret = arch_ctrlc();
-#else
- if (tstc() && getchar() == 3)
- ret = 1;
-#endif
+ if (IS_ENABLED(CONFIG_ARCH_HAS_CTRLC))
+ ret = arch_ctrlc();
+ else
+ ret = console_ctrlc();
if (ret)
ctrlc_abort = 1;
diff --git a/common/console_simple.c b/common/console_simple.c
index 6771d457455e..97beec2d8d2e 100644
--- a/common/console_simple.c
+++ b/common/console_simple.c
@@ -80,6 +80,16 @@ int pollchar(ktime_t duration)
}
EXPORT_SYMBOL(pollchar);
+/**
+ * console_ctrlc - check the console input for a Ctrl-C
+ *
+ * Return: true if Ctrl-C was pressed
+ */
+bool console_ctrlc(void)
+{
+ return tstc() && getchar() == 3;
+}
+
void console_flush(void)
{
if (console && console->flush)
diff --git a/include/console.h b/include/console.h
index 4b2893d5c4df..6469802531d5 100644
--- a/include/console.h
+++ b/include/console.h
@@ -239,9 +239,7 @@ static inline int barebox_set_loglevel(int loglevel)
}
#endif
-#ifdef CONFIG_ARCH_HAS_CTRLC
int arch_ctrlc(void);
-#endif
#ifndef CONFIG_CONSOLE_NONE
/* stdout */
@@ -255,6 +253,7 @@ int console_vprintf(struct console_device *con, const char *fmt, va_list args);
int ctrlc(void);
int ctrlc_non_interruptible(void);
+bool console_ctrlc(void);
void ctrlc_handled(void);
void console_ctrlc_allow(void);
void console_ctrlc_forbid(void);
@@ -266,6 +265,7 @@ static inline void console_flush(void) {}
/* test if ctrl-c was pressed */
static inline int ctrlc (void) { return 0; }
static inline int ctrlc_non_interruptible(void) { return 0; }
+static inline bool console_ctrlc(void) { return false; }
static inline void ctrlc_handled(void) { }
static inline void console_ctrlc_allow(void) { }
static inline void console_ctrlc_forbid(void) { }
--
2.47.3
More information about the barebox
mailing list