From 1953f6b70c4738c79cea76efda3853beb41bc52b Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 4 Aug 2022 10:28:45 +0200 Subject: [PATCH 2/2] add C2X %b scanf format --- src/internal/intscan.c | 10 +++++++--- src/stdio/vfscanf.c | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/internal/intscan.c b/src/internal/intscan.c index a4a5ae86..74c13be0 100644 --- a/src/internal/intscan.c +++ b/src/internal/intscan.c @@ -40,15 +40,19 @@ unsigned long long __intscan(FILE *f, unsigned base, int pok, unsigned long long } if ((base == 0 || base == 16) && c=='0') { c = shgetc(f); - if ((c|32)=='x') { + if (((c|32)=='x') || (c == 'b')) { + if (c == 'b') { + base = 2; + } else { + base = 16; + } c = shgetc(f); - if (val[c]>=16) { + if (val[c]>=base) { shunget(f); if (pok) shunget(f); else shlim(f, 0); return 0; } - base = 16; } else if (base == 0) { base = 8; } diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c index b78a374d..420f005a 100644 --- a/src/stdio/vfscanf.c +++ b/src/stdio/vfscanf.c @@ -151,7 +151,7 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) size = SIZE_L; break; case 'd': case 'i': case 'o': case 'u': case 'x': - case 'a': case 'e': case 'f': case 'g': + case 'a': case 'e': case 'f': case 'g': case 'b': case 'A': case 'E': case 'F': case 'G': case 'X': case 's': case 'c': case '[': case 'S': case 'C': @@ -286,6 +286,9 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) case 'o': base = 8; goto int_common; + case 'b': + base = 2; + goto int_common; case 'd': case 'u': base = 10; -- 2.39.2