1
0
Fork 0

feat(printf): added vprintf() support

Closes #43
development
Marco Paland 6 years ago
parent 87e1c834f7
commit 637df9333d

@ -884,6 +884,13 @@ int snprintf_(char* buffer, size_t count, const char* format, ...)
} }
int vprintf_(const char* format, va_list va)
{
char buffer[1];
return _vsnprintf(_out_char, buffer, (size_t)-1, format, va);
}
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va) int vsnprintf_(char* buffer, size_t count, const char* format, va_list va)
{ {
return _vsnprintf(_out_buffer, buffer, count, format, va); return _vsnprintf(_out_buffer, buffer, count, format, va);

@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// \author (c) Marco Paland (info@paland.com) // \author (c) Marco Paland (info@paland.com)
// 2014-2018, PALANDesign Hannover, Germany // 2014-2019, PALANDesign Hannover, Germany
// //
// \license The MIT License (MIT) // \license The MIT License (MIT)
// //
@ -77,6 +77,7 @@ int sprintf_(char* buffer, const char* format, ...);
* \param buffer A pointer to the buffer where to store the formatted string * \param buffer A pointer to the buffer where to store the formatted string
* \param count The maximum number of characters to store in the buffer, including a terminating null character * \param count The maximum number of characters to store in the buffer, including a terminating null character
* \param format A string that specifies the format of the output * \param format A string that specifies the format of the output
* \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 * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
* If the formatted string is truncated the buffer size (count) is returned * If the formatted string is truncated the buffer size (count) is returned
*/ */
@ -86,6 +87,16 @@ int snprintf_(char* buffer, size_t count, const char* format, ...);
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va); int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);
/**
* Tiny vprintf implementation
* \param format A string that specifies the format of the output
* \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_
int vprintf_(const char* format, va_list va);
/** /**
* printf with output function * printf with output function
* You may use this as dynamic alternative to printf() with its fixed _putchar() output * You may use this as dynamic alternative to printf() with its fixed _putchar() output

@ -85,6 +85,13 @@ TEST_CASE("snprintf", "[]" ) {
REQUIRE(!strcmp(buffer, "-1")); REQUIRE(!strcmp(buffer, "-1"));
} }
static void vprintf_builder_1(char* buffer, ...)
{
va_list args;
va_start(args, buffer);
test::vprintf("%d", args);
va_end(args);
}
static void vsnprintf_builder_1(char* buffer, ...) static void vsnprintf_builder_1(char* buffer, ...)
{ {
@ -103,6 +110,17 @@ static void vsnprintf_builder_3(char* buffer, ...)
} }
TEST_CASE("vprintf", "[]" ) {
char buffer[100];
printf_idx = 0U;
memset(printf_buffer, 0xCC, 100U);
vprintf_builder_1(buffer, 2345);
REQUIRE(printf_buffer[4] == (char)0xCC);
printf_buffer[4] = 0;
REQUIRE(!strcmp(printf_buffer, "2345"));
}
TEST_CASE("vsnprintf", "[]" ) { TEST_CASE("vsnprintf", "[]" ) {
char buffer[100]; char buffer[100];

Loading…
Cancel
Save