Skip to content

Commit c3107dd

Browse files
committed
Fixes #88: All non-va-list XXXprintf_() functions now use their va-list corresponding functions rather than directly calling _vnsprintf() - reducing some code duplication.
1 parent 2b63a30 commit c3107dd

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/printf/printf.c

+26-25
Original file line numberDiff line numberDiff line change
@@ -1235,12 +1235,34 @@ static int _vsnprintf(out_fct_type out, char* buffer, printf_size_t maxlen, cons
12351235

12361236
///////////////////////////////////////////////////////////////////////////////
12371237

1238+
int vprintf_(const char* format, va_list va)
1239+
{
1240+
char buffer[1];
1241+
return _vsnprintf(&out_putchar, buffer, (printf_size_t)-1, format, va);
1242+
}
1243+
1244+
int vsprintf_(char* buffer, const char* format, va_list va)
1245+
{
1246+
return _vsnprintf(out_buffer, buffer, (printf_size_t)-1, format, va);
1247+
}
1248+
1249+
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va)
1250+
{
1251+
return _vsnprintf(out_buffer, buffer, count, format, va);
1252+
}
1253+
1254+
int vfctprintf(void (*out)(char character, void* arg), void* arg, const char* format, va_list va)
1255+
{
1256+
const out_function_wrapper_type out_fct_wrap = { out, arg };
1257+
return _vsnprintf(out_wrapped_function, (char*)(uintptr_t)&out_fct_wrap, (printf_size_t)-1, format, va);
1258+
}
1259+
1260+
12381261
int printf_(const char* format, ...)
12391262
{
12401263
va_list va;
12411264
va_start(va, format);
1242-
char buffer[1];
1243-
const int ret = _vsnprintf(&out_putchar, buffer, (printf_size_t)-1, format, va);
1265+
const int ret = vprintf_(format, va);
12441266
va_end(va);
12451267
return ret;
12461268
}
@@ -1249,7 +1271,7 @@ int sprintf_(char* buffer, const char* format, ...)
12491271
{
12501272
va_list va;
12511273
va_start(va, format);
1252-
const int ret = _vsnprintf(out_buffer, buffer, (printf_size_t)-1, format, va);
1274+
const int ret = vsprintf_(buffer, format, va);
12531275
va_end(va);
12541276
return ret;
12551277
}
@@ -1258,27 +1280,11 @@ int snprintf_(char* buffer, size_t count, const char* format, ...)
12581280
{
12591281
va_list va;
12601282
va_start(va, format);
1261-
const int ret = _vsnprintf(out_buffer, buffer, count, format, va);
1283+
const int ret = vsnprintf_(buffer, count, format, va);
12621284
va_end(va);
12631285
return ret;
12641286
}
12651287

1266-
int vprintf_(const char* format, va_list va)
1267-
{
1268-
char buffer[1];
1269-
return _vsnprintf(&out_putchar, buffer, (printf_size_t)-1, format, va);
1270-
}
1271-
1272-
int vsprintf_(char* buffer, const char* format, va_list va)
1273-
{
1274-
return _vsnprintf(out_buffer, buffer, (printf_size_t)-1, format, va);
1275-
}
1276-
1277-
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va)
1278-
{
1279-
return _vsnprintf(out_buffer, buffer, count, format, va);
1280-
}
1281-
12821288
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...)
12831289
{
12841290
va_list va;
@@ -1288,11 +1294,6 @@ int fctprintf(void (*out)(char character, void* arg), void* arg, const char* for
12881294
return ret;
12891295
}
12901296

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

12971298
#ifdef __cplusplus
12981299
} // extern "C"

0 commit comments

Comments
 (0)