forked from Mirror/frr
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)
This commit is contained in:
parent
53df20fa68
commit
3ca2253b13
|
@ -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);
|
||||
|
|
|
@ -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*/
|
||||
|
|
Loading…
Reference in a new issue