Skip to content

Commit

Permalink
Fixes #88: All non-va-list XXXprintf_() functions now use their va-…
Browse files Browse the repository at this point in the history
…list corresponding functions rather than directly calling `_vnsprintf()` - reducing some code duplication.
  • Loading branch information
eyalroz committed Jan 26, 2022
1 parent 2b63a30 commit c3107dd
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions src/printf/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,12 +1235,34 @@ static int _vsnprintf(out_fct_type out, char* buffer, printf_size_t maxlen, cons

///////////////////////////////////////////////////////////////////////////////

int vprintf_(const char* format, va_list va)
{
char buffer[1];
return _vsnprintf(&out_putchar, buffer, (printf_size_t)-1, format, va);
}

int vsprintf_(char* buffer, const char* format, va_list va)
{
return _vsnprintf(out_buffer, buffer, (printf_size_t)-1, format, va);
}

int vsnprintf_(char* buffer, size_t count, const char* format, va_list va)
{
return _vsnprintf(out_buffer, buffer, count, format, va);
}

int vfctprintf(void (*out)(char character, void* arg), void* arg, const char* format, va_list va)
{
const out_function_wrapper_type out_fct_wrap = { out, arg };
return _vsnprintf(out_wrapped_function, (char*)(uintptr_t)&out_fct_wrap, (printf_size_t)-1, format, va);
}


int printf_(const char* format, ...)
{
va_list va;
va_start(va, format);
char buffer[1];
const int ret = _vsnprintf(&out_putchar, buffer, (printf_size_t)-1, format, va);
const int ret = vprintf_(format, va);
va_end(va);
return ret;
}
Expand All @@ -1249,7 +1271,7 @@ int sprintf_(char* buffer, const char* format, ...)
{
va_list va;
va_start(va, format);
const int ret = _vsnprintf(out_buffer, buffer, (printf_size_t)-1, format, va);
const int ret = vsprintf_(buffer, format, va);
va_end(va);
return ret;
}
Expand All @@ -1258,27 +1280,11 @@ int snprintf_(char* buffer, size_t count, const char* format, ...)
{
va_list va;
va_start(va, format);
const int ret = _vsnprintf(out_buffer, buffer, count, format, va);
const int ret = vsnprintf_(buffer, count, format, va);
va_end(va);
return ret;
}

int vprintf_(const char* format, va_list va)
{
char buffer[1];
return _vsnprintf(&out_putchar, buffer, (printf_size_t)-1, format, va);
}

int vsprintf_(char* buffer, const char* format, va_list va)
{
return _vsnprintf(out_buffer, buffer, (printf_size_t)-1, format, va);
}

int vsnprintf_(char* buffer, size_t count, const char* format, va_list va)
{
return _vsnprintf(out_buffer, buffer, count, format, va);
}

int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...)
{
va_list va;
Expand All @@ -1288,11 +1294,6 @@ int fctprintf(void (*out)(char character, void* arg), void* arg, const char* for
return ret;
}

int vfctprintf(void (*out)(char character, void* arg), void* arg, const char* format, va_list va)
{
const out_function_wrapper_type out_fct_wrap = { out, arg };
return _vsnprintf(out_wrapped_function, (char*)(uintptr_t)&out_fct_wrap, (printf_size_t)-1, format, va);
}

#ifdef __cplusplus
} // extern "C"
Expand Down

0 comments on commit c3107dd

Please sign in to comment.