1
0
Fork 0

feat(printf): added PRINTF_OVERRIDE_LIBC support

Fixes #16
development
Marco Paland 7 years ago
parent cc8f3bc050
commit 54dfd18543

@ -160,6 +160,8 @@ int length = sprintf(NULL, "Hello, world"); // length is set to 12
| Name | Default value | Description |
|------|---------------|-------------|
| PRINTF_INCLUDE_CONFIG_H | undefined | Define this as compiler switch (e.g. `gcc -DPRINTF_INCLUDE_CONFIG_H`) to include a "printf_config.h" definition file |
| PRINTF_OVERRIDE_LIBC | undefined | Define this to override the LIBC function declarations by using `printf_()` instead of `printf()` directly |
| PRINTF_NTOA_BUFFER_SIZE | 32 | ntoa (integer) conversion buffer size. This must be big enough to hold one converted numeric number _including_ leading zeros, normally 32 is a sufficient value. Created on the stack |
| PRINTF_FTOA_BUFFER_SIZE | 32 | ftoa (float) conversion buffer size. This must be big enough to hold one converted float number _including_ leading zeros, normally 32 is a sufficient value. Created on the stack |
| PRINTF_SUPPORT_FLOAT | defined | Define this to enable floating point (%f) support |

@ -699,8 +699,11 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
///////////////////////////////////////////////////////////////////////////////
#ifndef PRINTF_OVERRIDE_LIBC
int printf(const char* format, ...)
#else
int printf_(const char* format, ...)
#endif
{
va_list va;
va_start(va, format);
@ -711,7 +714,11 @@ int printf(const char* format, ...)
}
#ifndef PRINTF_OVERRIDE_LIBC
int sprintf(char* buffer, const char* format, ...)
#else
int sprintf_(char* buffer, const char* format, ...)
#endif
{
va_list va;
va_start(va, format);
@ -721,7 +728,11 @@ int sprintf(char* buffer, const char* format, ...)
}
#ifndef PRINTF_OVERRIDE_LIBC
int snprintf(char* buffer, size_t count, const char* format, ...)
#else
int snprintf_(char* buffer, size_t count, const char* format, ...)
#endif
{
va_list va;
va_start(va, format);
@ -731,13 +742,21 @@ int snprintf(char* buffer, size_t count, const char* format, ...)
}
#ifndef PRINTF_OVERRIDE_LIBC
int vsnprintf(char* buffer, size_t count, const char* format, va_list va)
#else
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va)
#endif
{
return _vsnprintf(_out_buffer, buffer, count, format, va);
}
#ifndef PRINTF_OVERRIDE_LIBC
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...)
#else
int fctprintf_(void (*out)(char character, void* arg), void* arg, const char* format, ...)
#endif
{
va_list va;
va_start(va, format);

@ -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
}

Loading…
Cancel
Save