Skip to content

Commit 47e9801

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 db74ee3 commit 47e9801

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
@@ -1230,12 +1230,34 @@ static int _vsnprintf(out_fct_type out, char* buffer, printf_size_t maxlen, cons
12301230

12311231
///////////////////////////////////////////////////////////////////////////////
12321232

1233+
int vprintf_(const char* format, va_list va)
1234+
{
1235+
char buffer[1];
1236+
return _vsnprintf(&out_putchar, buffer, (printf_size_t)-1, format, va);
1237+
}
1238+
1239+
int vsprintf_(char* buffer, const char* format, va_list va)
1240+
{
1241+
return _vsnprintf(out_buffer, buffer, (printf_size_t)-1, format, va);
1242+
}
1243+
1244+
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va)
1245+
{
1246+
return _vsnprintf(out_buffer, buffer, count, format, va);
1247+
}
1248+
1249+
int vfctprintf(void (*out)(char character, void* arg), void* arg, const char* format, va_list va)
1250+
{
1251+
const out_function_wrapper_type out_fct_wrap = { out, arg };
1252+
return _vsnprintf(out_wrapped_function, (char*)(uintptr_t)&out_fct_wrap, (printf_size_t)-1, format, va);
1253+
}
1254+
1255+
12331256
int printf_(const char* format, ...)
12341257
{
12351258
va_list va;
12361259
va_start(va, format);
1237-
char buffer[1];
1238-
const int ret = _vsnprintf(&out_putchar, buffer, (printf_size_t)-1, format, va);
1260+
const int ret = vprintf_(format, va);
12391261
va_end(va);
12401262
return ret;
12411263
}
@@ -1244,7 +1266,7 @@ int sprintf_(char* buffer, const char* format, ...)
12441266
{
12451267
va_list va;
12461268
va_start(va, format);
1247-
const int ret = _vsnprintf(out_buffer, buffer, (printf_size_t)-1, format, va);
1269+
const int ret = vsprintf_(buffer, format, va);
12481270
va_end(va);
12491271
return ret;
12501272
}
@@ -1253,27 +1275,11 @@ int snprintf_(char* buffer, size_t count, const char* format, ...)
12531275
{
12541276
va_list va;
12551277
va_start(va, format);
1256-
const int ret = _vsnprintf(out_buffer, buffer, count, format, va);
1278+
const int ret = vsnprintf_(buffer, count, format, va);
12571279
va_end(va);
12581280
return ret;
12591281
}
12601282

1261-
int vprintf_(const char* format, va_list va)
1262-
{
1263-
char buffer[1];
1264-
return _vsnprintf(&out_putchar, buffer, (printf_size_t)-1, format, va);
1265-
}
1266-
1267-
int vsprintf_(char* buffer, const char* format, va_list va)
1268-
{
1269-
return _vsnprintf(out_buffer, buffer, (printf_size_t)-1, format, va);
1270-
}
1271-
1272-
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va)
1273-
{
1274-
return _vsnprintf(out_buffer, buffer, count, format, va);
1275-
}
1276-
12771283
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...)
12781284
{
12791285
va_list va;
@@ -1283,11 +1289,6 @@ int fctprintf(void (*out)(char character, void* arg), void* arg, const char* for
12831289
return ret;
12841290
}
12851291

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

12921293
#ifdef __cplusplus
12931294
} // extern "C"

0 commit comments

Comments
 (0)