From: Ahmad Fatoum <[email protected]> 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 <[email protected]> --- 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
