From 3ca2253b13a871c97d72a014a261b41d7f75a660 Mon Sep 17 00:00:00 2001 From: Dag-Erling Smørgrav Date: Mon, 28 Aug 2023 15:32:23 +0000 Subject: lib/printf: Implement N2630. This adds formatted input/output of binary integer numbers to the printf(), scanf(), and strtol() families, including their wide-character counterparts. Reviewed by: imp, emaste Differential Revision: https://reviews.freebsd.org/D41511 FRR changes only include printf(), scanf/strtol are not locally implemented in FRR. Signed-off-by: David Lamparter (cherry picked from FreeBSD commit d9dc1603d6e48cca84cad3ebe859129131b8387c) --- lib/printf/vfprintf.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/printf/vfprintf.c') diff --git a/lib/printf/vfprintf.c b/lib/printf/vfprintf.c index 1290d08648..78f8be05cb 100644 --- a/lib/printf/vfprintf.c +++ b/lib/printf/vfprintf.c @@ -419,6 +419,19 @@ reswitch: switch (ch) { case 'z': flags |= SIZET; goto rflag; + case 'B': + case 'b': + if (flags & INTMAX_SIZE) + ujval = UJARG(); + else + ulval = UARG(); + base = 2; + /* leading 0b/B only if non-zero */ + if (flags & ALT && + (flags & INTMAX_SIZE ? ujval != 0 : ulval != 0)) + ox[1] = ch; + goto nosign; + break; case 'C': flags |= LONGINT; /*FALLTHROUGH*/ -- cgit v1.2.3