summaryrefslogtreecommitdiff
path: root/src/stdio/vsscanf.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-04-16 16:03:45 -0400
committerRich Felker <dalias@aerifal.cx>2012-04-16 16:03:45 -0400
commit18efeb320b763e541a7dbf61a7da1cbe13ab2be9 (patch)
treef8eb42a87b9c07ad8d9de0380356af3541b425aa /src/stdio/vsscanf.c
parentcc762434d91a2f441a1d2f44962ab1d4854b607b (diff)
downloadmusl-18efeb320b763e541a7dbf61a7da1cbe13ab2be9.tar.gz
new scanf implementation and corresponding integer parser/converter
advantages over the old code: - correct results for floating point (old code was bogus) - wide/regular scanf separated so scanf does not pull in wide code - well-defined behavior on integers that overflow dest type - support for %[a-b] ranges with %[ (impl-defined by widely used) - no intermediate conversion of fmt string to wide string - cleaner, easier to share code with strto* functions - better standards conformance for corner cases the old code remains in the source tree, as the wide versions of the scanf-family functions are still using it. it will be removed when no longer needed.
Diffstat (limited to 'src/stdio/vsscanf.c')
-rw-r--r--src/stdio/vsscanf.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/stdio/vsscanf.c b/src/stdio/vsscanf.c
index fd48f709..fbc15e69 100644
--- a/src/stdio/vsscanf.c
+++ b/src/stdio/vsscanf.c
@@ -1,21 +1,15 @@
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
+#include "stdio_impl.h"
-#include "__scanf.h"
-
-static void s_read(rctx_t *r)
+static size_t do_read(FILE *f, unsigned char *buf, size_t len)
{
- unsigned char *s = r->opaque;
- if (!s[r->l]) r->c = -1;
- else r->c = s[r->l++];
+ return __string_read(f, buf, len);
}
int vsscanf(const char *s, const char *fmt, va_list ap)
{
- size_t l = strlen(fmt), i;
- wchar_t fmt2[l+1];
- rctx_t r = { s_read, (void *)s, 0, isspace };
- for (i=0; i<=l; i++) fmt2[i] = (unsigned char)fmt[i];
- return __scanf(&r, fmt2, ap);
+ FILE f = {
+ .buf = (void *)s, .cookie = (void *)s,
+ .read = do_read, .lock = -1
+ };
+ return vfscanf(&f, fmt, ap);
}