vfprintf(3): Add support for kernel %b format
This is a direct port of the kernel %b format. I'm unclear on if (more) non-portable printf extensions will be a problem. I think it's desirable to have userspace formats include all kernel formats, but there may be competing goals I'm not aware of. Reviewed by: no one, unfortunately Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D8426
This commit is contained in:
parent
93326017f6
commit
ec055aeff5
@ -611,6 +611,37 @@ reswitch: switch (ch) {
|
|||||||
case 'z':
|
case 'z':
|
||||||
flags |= SIZET;
|
flags |= SIZET;
|
||||||
goto rflag;
|
goto rflag;
|
||||||
|
case 'b':
|
||||||
|
{
|
||||||
|
const char *q;
|
||||||
|
int anybitset, bit;
|
||||||
|
|
||||||
|
ulval = (u_int)GETARG(int);
|
||||||
|
cp = GETARG(char *);
|
||||||
|
|
||||||
|
q = __ultoa(ulval, buf + BUF, *cp++, 0, xdigs_lower);
|
||||||
|
PRINT(q, buf + BUF - q);
|
||||||
|
|
||||||
|
if (ulval == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
for (anybitset = 0; *cp;) {
|
||||||
|
bit = *cp++;
|
||||||
|
if (ulval & (1 << (bit - 1))) {
|
||||||
|
PRINT(anybitset ? "," : "<", 1);
|
||||||
|
q = cp;
|
||||||
|
for (; (bit = *cp) > ' '; ++cp)
|
||||||
|
continue;
|
||||||
|
PRINT(q, cp - q);
|
||||||
|
anybitset = 1;
|
||||||
|
} else
|
||||||
|
for (; *cp > ' '; ++cp)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (anybitset)
|
||||||
|
PRINT(">", 1);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
case 'C':
|
case 'C':
|
||||||
flags |= LONGINT;
|
flags |= LONGINT;
|
||||||
/*FALLTHROUGH*/
|
/*FALLTHROUGH*/
|
||||||
|
Loading…
Reference in New Issue
Block a user