mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/4] include: move sprintf prototypes to new linux/sprintf.h
Date: Fri, 28 Nov 2025 13:50:04 +0100	[thread overview]
Message-ID: <20251128125616.136559-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251128125616.136559-1-a.fatoum@pengutronix.de>

From: Ahmad Fatoum <a.fatoum@barebox.org>

The <stdio.h> header mixes console and sprintf functionality. Get a
little closer to the Linux split by moving the sprintf family of
functions to <linux/sprintf.h>.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 include/linux/sprintf.h | 48 +++++++++++++++++++++++++++++++++++++++++
 include/stdio.h         | 39 +--------------------------------
 2 files changed, 49 insertions(+), 38 deletions(-)
 create mode 100644 include/linux/sprintf.h

diff --git a/include/linux/sprintf.h b/include/linux/sprintf.h
new file mode 100644
index 000000000000..349773d3e16a
--- /dev/null
+++ b/include/linux/sprintf.h
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_KERNEL_SPRINTF_H_
+#define _LINUX_KERNEL_SPRINTF_H_
+
+#include <linux/types.h>
+#include <stdarg.h>
+
+int sprintf(char *buf, const char *fmt, ...) __printf(2, 3);
+int snprintf(char *buf, size_t size, const char *fmt, ...) __printf(3, 4);
+int scnprintf(char *buf, size_t size, const char *fmt, ...) __printf(3, 4);
+int vsprintf(char *buf, const char *fmt, va_list args);
+int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
+int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
+
+#if IN_PROPER || defined(CONFIG_PBL_CONSOLE)
+int asprintf(char **strp, const char *fmt, ...) __printf(2, 3);
+char *bvasprintf(const char *fmt, va_list ap);
+int vasprintf(char **strp, const char *fmt, va_list ap);
+int vrasprintf(char **strp, const char *fmt, va_list ap);
+int rasprintf(char **strp, const char *fmt, ...) __printf(2, 3);
+#else
+static inline __printf(2, 3) int asprintf(char **strp, const char *fmt, ...)
+{
+	return -1;
+}
+static inline char *bvasprintf(const char *fmt, va_list ap)
+{
+	return NULL;
+}
+static inline int vasprintf(char **strp, const char *fmt, va_list ap)
+{
+	return -1;
+}
+static inline int vrasprintf(char **strp, const char *fmt, va_list ap)
+{
+	return -1;
+}
+static inline __printf(2, 3) int rasprintf(char **strp, const char *fmt, ...)
+{
+	return -1;
+}
+#endif
+
+#define basprintf xasprintf
+
+const char *size_human_readable(unsigned long long size);
+
+#endif	/* _LINUX_KERNEL_SPRINTF_H */
diff --git a/include/stdio.h b/include/stdio.h
index f3e430b3b3d5..c0043b08bcc5 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -6,47 +6,11 @@
 #include <console.h>
 #include <printf.h>
 #include <xfuncs.h>
+#include <linux/sprintf.h>
 
 /*
  * STDIO based functions (can always be used)
  */
-int sprintf(char *buf, const char *fmt, ...) __printf(2, 3);
-int snprintf(char *buf, size_t size, const char *fmt, ...) __printf(3, 4);
-int scnprintf(char *buf, size_t size, const char *fmt, ...) __printf(3, 4);
-int vsprintf(char *buf, const char *fmt, va_list args);
-int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
-int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
-
-#if IN_PROPER || defined(CONFIG_PBL_CONSOLE)
-int asprintf(char **strp, const char *fmt, ...) __printf(2, 3);
-char *bvasprintf(const char *fmt, va_list ap);
-int vasprintf(char **strp, const char *fmt, va_list ap);
-int vrasprintf(char **strp, const char *fmt, va_list ap);
-int rasprintf(char **strp, const char *fmt, ...) __printf(2, 3);
-#else
-static inline __printf(2, 3) int asprintf(char **strp, const char *fmt, ...)
-{
-	return -1;
-}
-static inline char *bvasprintf(const char *fmt, va_list ap)
-{
-	return NULL;
-}
-static inline int vasprintf(char **strp, const char *fmt, va_list ap)
-{
-	return -1;
-}
-static inline int vrasprintf(char **strp, const char *fmt, va_list ap)
-{
-	return -1;
-}
-static inline __printf(2, 3) int rasprintf(char **strp, const char *fmt, ...)
-{
-	return -1;
-}
-#endif
-
-#define basprintf xasprintf
 
 #ifdef CONFIG_ARCH_HAS_CTRLC
 int arch_ctrlc(void);
@@ -113,7 +77,6 @@ static inline void console_ctrlc_allow(void) { }
 static inline void console_ctrlc_forbid(void) { }
 #endif
 
-const char *size_human_readable(unsigned long long size);
 int readline(const char *prompt, char *buf, int len);
 
 #if (IN_PROPER && !defined(CONFIG_CONSOLE_NONE)) || \
-- 
2.47.3




  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 ` Ahmad Fatoum [this message]
2025-11-28 12:50 ` [PATCH 4/4] console: move non-stdio elements to console.h Ahmad Fatoum
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-3-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