From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/4] console: move non-stdio elements to console.h
Date: Fri, 28 Nov 2025 13:50:05 +0100 [thread overview]
Message-ID: <20251128125616.136559-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251128125616.136559-1-a.fatoum@pengutronix.de>
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@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
next prev parent reply other threads:[~2025-11-28 12:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-28 12:50 [PATCH 1/4] printf: define printk/no_printk in terms of prints Ahmad Fatoum
2025-11-28 12:50 ` [PATCH 2/4] bug: add support for CONFIG_DEBUG_BUGVERBOSE Ahmad Fatoum
2025-11-28 12:50 ` [PATCH 3/4] include: move sprintf prototypes to new linux/sprintf.h Ahmad Fatoum
2025-11-28 12:50 ` Ahmad Fatoum [this message]
2025-12-01 10:22 ` [PATCH 1/4] printf: define printk/no_printk in terms of prints Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251128125616.136559-4-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox