diff --git a/printf.c b/printf.c index 8a700ad..598b6a9 100644 --- a/printf.c +++ b/printf.c @@ -36,14 +36,6 @@ #include "printf.h" -// define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H ...) to include the -// printf_config.h header file -// default: undefined -#ifdef PRINTF_INCLUDE_CONFIG_H -#include "printf_config.h" -#endif - - // 'ntoa' conversion buffer size, this must be big enough to hold one converted // numeric number including padded zeros (dynamically created on stack) // default: 32 byte diff --git a/printf.h b/printf.h index 6104ccf..eaf85c6 100644 --- a/printf.h +++ b/printf.h @@ -36,6 +36,22 @@ #include +// define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H ...) to include the +// printf_config.h header file +// default: undefined +#ifdef PRINTF_INCLUDE_CONFIG_H +#include "printf_config.h" +#endif + + +// avoid conflicts with standard library APIs by using underscore-appended +// function names +// default: activated +#ifndef PRINTF_ALLOW_STDLIB_CONFLICTS +#define PRINTF_AVOID_STDLIB_CONFLICTS +#endif + + #ifdef __cplusplus extern "C" { #endif @@ -57,7 +73,11 @@ 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_ +#ifdef PRINTF_AVOID_STDLIB_CONFLICTS +#define printf printf_ +#else +#define printf_ printf +#endif int printf_(const char* format, ...); @@ -68,7 +88,11 @@ 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_ +#ifdef PRINTF_AVOID_STDLIB_CONFLICTS +#define sprintf sprintf_ +#else +#define sprintf_ sprintf +#endif int sprintf_(char* buffer, const char* format, ...); @@ -82,8 +106,13 @@ 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_ +#ifdef PRINTF_AVOID_STDLIB_CONFLICTS +#define snprintf snprintf_ +#define vsnprintf vsnprintf_ +#else +#define snprintf_ snprintf +#define vsnprintf_ vsnprintf +#endif 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 +123,11 @@ 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_ +#ifdef PRINTF_AVOID_STDLIB_CONFLICTS +#define vprintf vprintf_ +#else +#define vprintf_ vprintf +#endif int vprintf_(const char* format, va_list va);