Page MenuHomeFreeBSD

vfprintf(3): Add support for kernel %b format
ClosedPublic

Authored by cem on Nov 3 2016, 12:50 AM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 14 2024, 1:09 AM
Unknown Object (File)
Jan 16 2024, 7:23 AM
Unknown Object (File)
Dec 30 2023, 11:05 AM
Unknown Object (File)
Dec 29 2023, 6:27 AM
Unknown Object (File)
Dec 20 2023, 6:10 PM
Unknown Object (File)
Nov 13 2023, 11:09 AM
Unknown Object (File)
Nov 6 2023, 5:33 AM
Unknown Object (File)
Oct 27 2023, 9:57 AM
Subscribers
None

Details

Summary

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.

I think das@ should review this as the most heavy printf committer, but they
don't appear to have a phabricator account.

Test Plan
#include <stdio.h>
void main(void) {
        printf("%b\n", 0x12345, "\20\01low\02med\21hi");
}

Should print: 12345<low,hi>

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

cem retitled this revision from to vfprintf(3): Add support for kernel %b format.
cem updated this object.
cem edited the test plan for this revision. (Show Details)
cem added reviewers: emaste, jilles.

I think there are lots of reasons we'd like to compile and use kernel code in userspace and having %b be available is certainly useful for that. On the other hand, if this becomes widely used in FreeBSD userland code it makes it harder to use that code in other projects or possibly build FreeBSD on other hosts.

Do you have an example use case in mind?

I think there are lots of reasons we'd like to compile and use kernel code in userspace and having %b be available is certainly useful for that. On the other hand, if this becomes widely used in FreeBSD userland code it makes it harder to use that code in other projects or possibly build FreeBSD on other hosts.

Yep!

Do you have an example use case in mind?

Yeah. At $WORK we've got an on-disk structure that is manipulated by userspace. It's got a few flags fields. We have a tool that prints out the on-disk structure in a human readable format. It'd be convenient to use %b, rather than re-implement %b, in that tool.

(I guess we ($WORK) could always carry it as a local libc patch — it's very self-contained. But I prefer not to do that if possible.)

Any strong objection to this?

This revision was automatically updated to reflect the committed changes.