From 66e17f133fdc803cb17de1cddbf550d8e49cd8d2 Mon Sep 17 00:00:00 2001 From: Patrik Bachan Date: Mon, 21 Dec 2020 17:23:06 +0100 Subject: [PATCH 1/2] allow function name remap by macro definition default names are mp_printf etc. to rename to epic_printf, add compiler arg: `-D'PRINTF_FUNCTION_RENAME\(base\)=epic_\#\#base'` (example taken from cmake, character escaping might differ) --- printf.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/printf.h b/printf.h index 6104ccfb..97025abf 100644 --- a/printf.h +++ b/printf.h @@ -40,7 +40,11 @@ extern "C" { #endif - +#if defined(PRINTF_FUNCTION_RENAME) + #define _PRINTF_GET_FNAME(base) PRINTF_FUNCTION_RENAME(base) +#else + #define _PRINTF_GET_FNAME(base) mp_base## +#endif /** * Output a character to a custom device like UART, used by the printf() function * This function is declared here only. You have to write your custom implementation somewhere @@ -57,7 +61,7 @@ void _putchar(char character); * \param format A string that specifies the format of the output * \return The number of characters that are written into the array, not counting the terminating null character */ -#define printf printf_ +#define printf_ _PRINTF_GET_FNAME(printf) int printf_(const char* format, ...); @@ -68,7 +72,7 @@ int printf_(const char* format, ...); * \param format A string that specifies the format of the output * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character */ -#define sprintf sprintf_ +#define sprintf_ _PRINTF_GET_FNAME(sprintf) int sprintf_(char* buffer, const char* format, ...); @@ -82,8 +86,8 @@ int sprintf_(char* buffer, const char* format, ...); * null character. A value equal or larger than count indicates truncation. Only when the returned value * is non-negative and less than count, the string has been completely written. */ -#define snprintf snprintf_ -#define vsnprintf vsnprintf_ +#define snprintf_ _PRINTF_GET_FNAME(snprintf) +#define vsnprintf_ _PRINTF_GET_FNAME(vsnprintf) int snprintf_(char* buffer, size_t count, const char* format, ...); int vsnprintf_(char* buffer, size_t count, const char* format, va_list va); @@ -94,7 +98,7 @@ int vsnprintf_(char* buffer, size_t count, const char* format, va_list va); * \param va A value identifying a variable arguments list * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character */ -#define vprintf vprintf_ +#define vprintf_ _PRINTF_GET_FNAME(vprintf) int vprintf_(const char* format, va_list va); From d64993631c52f96ef0beb8fd910719570b37f727 Mon Sep 17 00:00:00 2001 From: Patrik Bachan Date: Tue, 29 Dec 2020 21:34:42 +0100 Subject: [PATCH 2/2] fix default naming macro --- printf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printf.h b/printf.h index 97025abf..7caf2ec5 100644 --- a/printf.h +++ b/printf.h @@ -43,7 +43,7 @@ extern "C" { #if defined(PRINTF_FUNCTION_RENAME) #define _PRINTF_GET_FNAME(base) PRINTF_FUNCTION_RENAME(base) #else - #define _PRINTF_GET_FNAME(base) mp_base## + #define _PRINTF_GET_FNAME(base) mp_##base #endif /** * Output a character to a custom device like UART, used by the printf() function