[PATCH 4/4] console: move non-stdio elements to console.h

Ahmad Fatoum a.fatoum at pengutronix.de
Fri Nov 28 04:50:05 PST 2025


To prepare addition of more functions that hosted implementations
provide in stdio.h, let's move existing console functionality into the
console.h header, where they belong.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/console.h | 33 +++++++++++++++++
 include/stdio.h   | 93 +++++------------------------------------------
 2 files changed, 42 insertions(+), 84 deletions(-)

diff --git a/include/console.h b/include/console.h
index 37e127e175c9..149378fc2839 100644
--- a/include/console.h
+++ b/include/console.h
@@ -222,6 +222,39 @@ static inline int barebox_set_loglevel(int loglevel)
 }
 #endif
 
+#ifdef CONFIG_ARCH_HAS_CTRLC
+int arch_ctrlc(void);
+#endif
+
+#ifndef CONFIG_CONSOLE_NONE
+/* stdout */
+void console_putc(unsigned int ch, const char c);
+int console_puts(unsigned int ch, const char *s);
+void console_flush(void);
+
+int ctrlc(void);
+int ctrlc_non_interruptible(void);
+void ctrlc_handled(void);
+void console_ctrlc_allow(void);
+void console_ctrlc_forbid(void);
+#else
+static inline int console_puts(unsigned int ch, const char *str) { return 0; }
+static inline void console_putc(unsigned int ch, char c) {}
+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 void ctrlc_handled(void) { }
+static inline void console_ctrlc_allow(void) { }
+static inline void console_ctrlc_forbid(void) { }
+#endif
+
+#define STDIN_FILENO		0
+#define STDOUT_FILENO		1
+#define STDERR_FILENO		2
+#define MAX_FILES	128
+
 /**
  * clk_get_for_console - get clock, ignoring known unavailable clock controller
  * @dev: device for clock "consumer"
diff --git a/include/stdio.h b/include/stdio.h
index c0043b08bcc5..945ec4692609 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -8,100 +8,30 @@
 #include <xfuncs.h>
 #include <linux/sprintf.h>
 
-/*
- * STDIO based functions (can always be used)
- */
-
-#ifdef CONFIG_ARCH_HAS_CTRLC
-int arch_ctrlc(void);
-#endif
-
 #ifndef CONFIG_CONSOLE_NONE
 /* stdin */
 int tstc(void);
-
-/* stdout */
-void console_putc(unsigned int ch, const char c);
 int getchar(void);
-int console_puts(unsigned int ch, const char *s);
-void console_flush(void);
-
 int vprintf(const char *fmt, va_list args);
-
-int ctrlc(void);
-int ctrlc_non_interruptible(void);
-void ctrlc_handled(void);
-void console_ctrlc_allow(void);
-void console_ctrlc_forbid(void);
 #else
-static inline int tstc(void)
-{
-	return 0;
-}
-
-static inline int console_puts(unsigned int ch, const char *str)
-{
-	return 0;
-}
-
-static inline int getchar(void)
-{
-	return -EINVAL;
-}
-
-static inline void console_putc(unsigned int ch, char c) {}
-
-static inline void console_flush(void) {}
-
-static inline int vprintf(const char *fmt, va_list args)
-{
-	return 0;
-}
-
-/* test if ctrl-c was pressed */
-static inline int ctrlc (void)
-{
-	return 0;
-}
-
-static inline int ctrlc_non_interruptible(void)
-{
-	return 0;
-}
-
-static inline void ctrlc_handled(void)
-{
-}
-
-static inline void console_ctrlc_allow(void) { }
-static inline void console_ctrlc_forbid(void) { }
+static inline int tstc(void) { return 0; }
+static inline int vprintf(const char *fmt, va_list args) { return 0; }
+static inline int getchar(void) { return -EINVAL; }
 #endif
 
 int readline(const char *prompt, char *buf, int len);
 
 #if (IN_PROPER && !defined(CONFIG_CONSOLE_NONE)) || \
 	(IN_PBL && defined(CONFIG_PBL_CONSOLE))
-static inline int puts(const char *s)
-{
-	return console_puts(CONSOLE_STDOUT, s);
-}
-
-static inline void putchar(char c)
-{
-	console_putc(CONSOLE_STDOUT, c);
-}
+static inline int puts(const char *s) { return console_puts(CONSOLE_STDOUT, s); }
+static inline void putchar(char c) { console_putc(CONSOLE_STDOUT, c); }
 #else
-static inline int puts(const char *s)
-{
-	return 0;
-}
-
-static inline void putchar(char c)
-{
-	return;
-}
+static inline int puts(const char *s) { return 0; }
+static inline void putchar(char c) {}
 #endif
 
+int readline(const char *prompt, char *buf, int len);
+
 /*
  * FILE based functions
  */
@@ -116,11 +46,6 @@ static inline void putchar(char c)
 #define eputchar(ch)		dputc(STDERR_FILENO, ch)
 #endif
 
-#define STDIN_FILENO		0
-#define STDOUT_FILENO		1
-#define STDERR_FILENO		2
-#define MAX_FILES	128
-
 int vdprintf(int fd, const char *fmt, va_list args) ;
 int dprintf(int file, const char *fmt, ...) __printf(2, 3);
 int dputs(int file, const char *s);
-- 
2.47.3




More information about the barebox mailing list