From 00057a37163ca2aadf6f7646dd17ca90c4ae008d Mon Sep 17 00:00:00 2001 From: yinchuang Date: Tue, 25 Jul 2023 12:50:28 +0800 Subject: [PATCH] Optimize sscanf Issue:I7NQ5W Signed-off-by: yinchuang Test:libctest --- musl_src.gni | 1 + porting/linux/user/src/stdio/vsscanf.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 porting/linux/user/src/stdio/vsscanf.c diff --git a/musl_src.gni b/musl_src.gni index ef600af8..86008dea 100644 --- a/musl_src.gni +++ b/musl_src.gni @@ -2190,6 +2190,7 @@ musl_src_porting_file = [ "src/stdio/stderr.c", "src/stdio/fgets.c", "src/stdio/vsnprintf.c", + "src/stdio/vsscanf.c", "src/internal/stdio_impl.h", "src/internal/vdso.c", "src/time/clock_gettime.c", diff --git a/porting/linux/user/src/stdio/vsscanf.c b/porting/linux/user/src/stdio/vsscanf.c new file mode 100644 index 00000000..f0c4a7d0 --- /dev/null +++ b/porting/linux/user/src/stdio/vsscanf.c @@ -0,0 +1,21 @@ +#include "stdio_impl.h" +#include + +// Empty implementation because vfscanf operates rpos directly. +static size_t string_read(FILE *f, unsigned char *buf, size_t len) +{ + return 0; +} + +int vsscanf(const char *restrict s, const char *restrict fmt, va_list ap) +{ + size_t s_len = strlen(s); + FILE f = { + .buf = (void *)s, .cookie = (void *)s, + .read = string_read, .lock = -1, + .buf_size = s_len, .rpos = s, .rend = s + s_len, + }; + return vfscanf(&f, fmt, ap); +} + +weak_alias(vsscanf,__isoc99_vsscanf); -- GitLab