From 045e511d74affcec36981d51a3cc9900838e35fb Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Wed, 10 Oct 2018 11:30:25 +0900 Subject: [PATCH] libc: fscanf stubs --- base/usr/include/stdio.h | 2 ++ libc/stdio/scanf.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/base/usr/include/stdio.h b/base/usr/include/stdio.h index f5f10819..a1561f16 100644 --- a/base/usr/include/stdio.h +++ b/base/usr/include/stdio.h @@ -81,3 +81,5 @@ extern char * tmpnam(char * s); extern int vsscanf(const char *str, const char *format, va_list ap); extern int sscanf(const char *str, const char *format, ...); +extern int vfscanf(FILE * stream, const char *format, va_list ap); +extern int fscanf(FILE *stream, const char *format, ...); diff --git a/libc/stdio/scanf.c b/libc/stdio/scanf.c index 6fd77107..e88d74d1 100644 --- a/libc/stdio/scanf.c +++ b/libc/stdio/scanf.c @@ -22,6 +22,21 @@ int vsscanf(const char *str, const char *format, va_list ap) { return 0; } +int vfscanf(FILE * stream, const char *format, va_list ap) { + fprintf(stderr, "%s: fscanf(%d, format=%s, ...);\n", _argv_0, fileno(stream), format); + while (*format) { + if (*format == ' ') { + /* Handle whitespace */ + } else if (*format == '%') { + /* Parse */ + } else { + /* Expect exact character? */ + } + format++; + } + return 0; +} + int sscanf(const char *str, const char *format, ...) { va_list args; va_start(args, format); @@ -29,3 +44,11 @@ int sscanf(const char *str, const char *format, ...) { va_end(args); return out; } + +int fscanf(FILE *stream, const char *format, ...) { + va_list args; + va_start(args, format); + int out = vfscanf(stream, format, args); + va_end(args); + return out; +}