From 5606e77ee0d15a2b692695a216023568e7115c89 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Thu, 1 Jun 2023 11:23:12 +0800 Subject: [PATCH] libc/wchar: Implement vswprintf Implement vswprintf and let swprintf based on it. Signed-off-by: Huang Qi --- libs/libc/wchar/lib_swprintf.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/libs/libc/wchar/lib_swprintf.c b/libs/libc/wchar/lib_swprintf.c index af453aca0c..c2fc3a1d83 100644 --- a/libs/libc/wchar/lib_swprintf.c +++ b/libs/libc/wchar/lib_swprintf.c @@ -35,14 +35,13 @@ ****************************************************************************/ /**************************************************************************** - * swprintf + * vswprintf ****************************************************************************/ -int swprintf(FAR wchar_t *buf, size_t maxlen, FAR const wchar_t *fmt, ...) +int vswprintf(FAR wchar_t *buf, size_t maxlen, FAR const wchar_t *fmt, + va_list ap) { struct lib_memoutstream_s memoutstream; - va_list ap; - int n; /* Initialize a memory stream to write to the buffer */ @@ -51,9 +50,23 @@ int swprintf(FAR wchar_t *buf, size_t maxlen, FAR const wchar_t *fmt, ...) /* Then let lib_vsprintf do the real work */ + return lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, + (FAR const char *)fmt, ap); +} + +/**************************************************************************** + * swprintf + ****************************************************************************/ + +int swprintf(FAR wchar_t *buf, size_t maxlen, FAR const wchar_t *fmt, ...) +{ + va_list ap; + int n; + + /* Then let vswprintf do the real work */ + va_start(ap, fmt); - n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, - (FAR const char *)fmt, ap); + n = vswprintf(buf, maxlen, fmt, ap); va_end(ap); return n;