summaryrefslogtreecommitdiff
path: root/lib/printf/printfcommon.h
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2023-08-28 15:32:23 +0000
committerDavid Lamparter <equinox@opensourcerouting.org>2023-09-03 23:32:55 +0200
commit3ca2253b13a871c97d72a014a261b41d7f75a660 (patch)
tree811de60f6fa3309d2f8f8a1cdfd53a7dd7f9655a /lib/printf/printfcommon.h
parent53df20fa688c61772632dbd71118a2c46604eb53 (diff)
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 <equinox@opensourcerouting.org> (cherry picked from FreeBSD commit d9dc1603d6e48cca84cad3ebe859129131b8387c)
Diffstat (limited to 'lib/printf/printfcommon.h')
-rw-r--r--lib/printf/printfcommon.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/printf/printfcommon.h b/lib/printf/printfcommon.h
index 7285e7f5ac..b3a7ca0c13 100644
--- a/lib/printf/printfcommon.h
+++ b/lib/printf/printfcommon.h
@@ -169,6 +169,13 @@ __ultoa(u_long val, CHAR *endp, int base, int octzero, const char *xdigs)
} while (sval != 0);
break;
+ case 2:
+ do {
+ *--cp = to_char(val & 1);
+ val >>= 1;
+ } while (val);
+ break;
+
case 8:
do {
*--cp = to_char(val & 7);
@@ -219,6 +226,13 @@ __ujtoa(uintmax_t val, CHAR *endp, int base, int octzero, const char *xdigs)
} while (sval != 0);
break;
+ case 2:
+ do {
+ *--cp = to_char(val & 1);
+ val >>= 1;
+ } while (val);
+ break;
+
case 8:
do {
*--cp = to_char(val & 7);