summaryrefslogtreecommitdiff
path: root/src/stdio/__string_read.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/__string_read.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/__string_read.c')
-rw-r--r--src/stdio/__string_read.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/stdio/__string_read.c b/src/stdio/__string_read.c
new file mode 100644
index 00000000..5c3728d7
--- /dev/null
+++ b/src/stdio/__string_read.c
@@ -0,0 +1,13 @@
+#include "stdio_impl.h"
+
+size_t __string_read(FILE *f, unsigned char *buf, size_t len)
+{
+ char *src = f->cookie;
+ size_t k = strnlen(src, len+256);
+ if (k < len) len = k;
+ memcpy(buf, src, len);
+ f->rpos = (void *)(src+len);
+ f->rend = (void *)(src+k);
+ f->cookie = src+k;
+ return len;
+}