From ec2b2720f5af091b8c588b95f530e16286004090 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Thu, 2 Nov 2023 06:20:20 -0300 Subject: [PATCH] vcscanf: add floating point number scanner case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Handle all the documented format specifiers. Exit with error if given a length modifier other than "l". Skip spaces, initialize the buffer and then begin parsing. References: https://en.cppreference.com/w/c/io/fscanfî1;129A --- libc/stdio/vcscanf.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libc/stdio/vcscanf.c b/libc/stdio/vcscanf.c index b6ea00264..d68c4a5ea 100644 --- a/libc/stdio/vcscanf.c +++ b/libc/stdio/vcscanf.c @@ -225,6 +225,27 @@ int __vcscanf(int callback(void *), // base = 10; } goto DecodeNumber; + case 'a': + case 'A': + case 'e': + case 'E': + case 'f': + case 'F': + case 'g': + case 'G': // floating point number + if (!(charbytes == sizeof(char) || charbytes == sizeof(wchar_t))) { + items = -1; + goto Done; + } + while (isspace(c)) { + c = READ; + } + bufsize = BUFFER_GROW; + buf = malloc(bufsize); + bufcur = 0; + buf[bufcur++] = c; + buf[bufcur] = '\0'; + goto ConsumeFloatingPointNumber; default: items = einval(); goto Done;