Skip to content

Commit 66e17f1

Browse files
committed
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)
1 parent d3b9846 commit 66e17f1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

printf.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
extern "C" {
4141
#endif
4242

43-
43+
#if defined(PRINTF_FUNCTION_RENAME)
44+
#define _PRINTF_GET_FNAME(base) PRINTF_FUNCTION_RENAME(base)
45+
#else
46+
#define _PRINTF_GET_FNAME(base) mp_base##
47+
#endif
4448
/**
4549
* Output a character to a custom device like UART, used by the printf() function
4650
* This function is declared here only. You have to write your custom implementation somewhere
@@ -57,7 +61,7 @@ void _putchar(char character);
5761
* \param format A string that specifies the format of the output
5862
* \return The number of characters that are written into the array, not counting the terminating null character
5963
*/
60-
#define printf printf_
64+
#define printf_ _PRINTF_GET_FNAME(printf)
6165
int printf_(const char* format, ...);
6266

6367

@@ -68,7 +72,7 @@ int printf_(const char* format, ...);
6872
* \param format A string that specifies the format of the output
6973
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
7074
*/
71-
#define sprintf sprintf_
75+
#define sprintf_ _PRINTF_GET_FNAME(sprintf)
7276
int sprintf_(char* buffer, const char* format, ...);
7377

7478

@@ -82,8 +86,8 @@ int sprintf_(char* buffer, const char* format, ...);
8286
* null character. A value equal or larger than count indicates truncation. Only when the returned value
8387
* is non-negative and less than count, the string has been completely written.
8488
*/
85-
#define snprintf snprintf_
86-
#define vsnprintf vsnprintf_
89+
#define snprintf_ _PRINTF_GET_FNAME(snprintf)
90+
#define vsnprintf_ _PRINTF_GET_FNAME(vsnprintf)
8791
int snprintf_(char* buffer, size_t count, const char* format, ...);
8892
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);
8993

@@ -94,7 +98,7 @@ int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);
9498
* \param va A value identifying a variable arguments list
9599
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
96100
*/
97-
#define vprintf vprintf_
101+
#define vprintf_ _PRINTF_GET_FNAME(vprintf)
98102
int vprintf_(const char* format, va_list va);
99103

100104

0 commit comments

Comments
 (0)