diff options
| author | Donald Sharp <donaldsharp72@gmail.com> | 2024-03-11 10:32:32 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-11 10:32:32 -0400 |
| commit | c514e84979db731c5ca4d14797843cd330519402 (patch) | |
| tree | e520cc8332d6bb4a1f0f538b53ff38f7d0613fad /lib/printf/vfprintf.c | |
| parent | 0042ea49b5b91eb4c449936293fe5547d774838f (diff) | |
| parent | 02af04f73d547dd295c6e7d6ce34f2763b3b98ba (diff) | |
Merge pull request #15516 from opensourcerouting/freebsd-printf-sync-20240310
lib/printf: pick up ISO C23 / N2680 from FreeBSD
Diffstat (limited to 'lib/printf/vfprintf.c')
| -rw-r--r-- | lib/printf/vfprintf.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/printf/vfprintf.c b/lib/printf/vfprintf.c index 2083642d5e..3f6700c838 100644 --- a/lib/printf/vfprintf.c +++ b/lib/printf/vfprintf.c @@ -416,6 +416,49 @@ reswitch: switch (ch) { case 't': flags |= PTRDIFFT; goto rflag; + case 'w': + /* + * Fixed-width integer types. On all platforms we + * support, int8_t is equivalent to char, int16_t + * is equivalent to short, int32_t is equivalent + * to int, int64_t is equivalent to long long int. + * Furthermore, int_fast8_t, int_fast16_t and + * int_fast32_t are equivalent to int, and + * int_fast64_t is equivalent to long long int. + */ + flags &= ~(CHARINT|SHORTINT|LONGINT|LLONGINT|INTMAXT); + if (fmt[0] == 'f') { + flags |= FASTINT; + fmt++; + } else { + flags &= ~FASTINT; + } + if (fmt[0] == '8') { + if (!(flags & FASTINT)) + flags |= CHARINT; + else + (void) 0; /* no flag set = 32 */ + fmt += 1; + } else if (fmt[0] == '1' && fmt[1] == '6') { + if (!(flags & FASTINT)) + flags |= SHORTINT; + else + (void) 0; /* no flag set = 32 */ + fmt += 2; + } else if (fmt[0] == '3' && fmt[1] == '2') { + /* no flag set = 32 */ + fmt += 2; + } else if (fmt[0] == '6' && fmt[1] == '4') { + flags |= LLONGINT; + fmt += 2; + } else { + if (flags & FASTINT) { + flags &= ~FASTINT; + fmt--; + } + goto invalid; + } + goto rflag; case 'z': flags |= SIZET; goto rflag; @@ -684,6 +727,7 @@ number: if ((dprec = prec) >= 0) default: /* "%?" prints ?, unless ? is NUL */ if (ch == '\0') goto done; +invalid: /* pretend it was %c with argument ch */ buf[0] = ch; cp = buf; |
