From 54dfd185432d300746a8586cd3e620d5eb178a5d Mon Sep 17 00:00:00 2001 From: Marco Paland Date: Fri, 2 Nov 2018 14:00:03 +0100 Subject: feat(printf): added PRINTF_OVERRIDE_LIBC support Fixes #16 --- printf.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'printf.h') diff --git a/printf.h b/printf.h index b82e70f..69245cb 100644 --- a/printf.h +++ b/printf.h @@ -25,7 +25,7 @@ // \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on // embedded systems with a very limited resources. // Use this instead of bloated standard/newlib printf. -// These routines are thread safe and reentrant! +// These routines are thread safe and reentrant. // /////////////////////////////////////////////////////////////////////////////// @@ -56,6 +56,12 @@ extern "C" { void _putchar(char character); +// if PRINTF_OVERRIDE_LIBC is is defined, the regular printf() API is overridden by macro defines +// and internal underscore-appended functions like printf_() are used to avoid conflicts with +// LIBC defined printf() functions. +// default: undefined +#ifndef PRINTF_OVERRIDE_LIBC + /** * Tiny printf implementation * You have to implement _putchar if you use printf() @@ -97,6 +103,23 @@ int vsnprintf(char* buffer, size_t count, const char* format, va_list va); */ int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...); +#else // PRINTF_OVERRIDE_LIBC + +// override the LIBC defined function names +#define printf printf_ +#define sprintf sprintf_ +#define snprintf snprintf_ +#define vsnprintf vsnprintf_ +#define fctprintf fctprintf_ + +int printf_(const char* format, ...); +int sprintf_(char* buffer, const char* format, ...); +int snprintf_(char* buffer, size_t count, const char* format, ...); +int vsnprintf_(char* buffer, size_t count, const char* format, va_list va); +int fctprintf_(void (*out)(char character, void* arg), void* arg, const char* format, ...); + +#endif // PRINTF_OVERRIDE_LIBC + #ifdef __cplusplus } -- cgit v1.2.3