diff options
author | Marco Paland <marco@paland.com> | 2018-11-02 14:00:03 +0100 |
---|---|---|
committer | Marco Paland <marco@paland.com> | 2018-11-02 14:00:03 +0100 |
commit | 54dfd185432d300746a8586cd3e620d5eb178a5d (patch) | |
tree | 10720771a853e351438ea99c05ca6b1fe3195f95 /printf.h | |
parent | cc8f3bc050042270c661c0807d6555c242e0b244 (diff) | |
download | printf-54dfd185432d300746a8586cd3e620d5eb178a5d.tar.gz printf-54dfd185432d300746a8586cd3e620d5eb178a5d.tar.bz2 printf-54dfd185432d300746a8586cd3e620d5eb178a5d.zip |
feat(printf): added PRINTF_OVERRIDE_LIBC support
Fixes #16
Diffstat (limited to 'printf.h')
-rw-r--r-- | printf.h | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -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
}
|