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)
Fri, Dec 27, 8:54 PM
Unknown Object (File)
Dec 10 2024, 9:56 AM
Unknown Object (File)
Nov 26 2024, 4:17 AM
Unknown Object (File)
Oct 21 2024, 4:25 AM
Unknown Object (File)
Oct 2 2024, 10:56 PM
Unknown Object (File)
Oct 2 2024, 5:41 PM
Unknown Object (File)
Sep 18 2024, 3:18 AM
Unknown Object (File)
Sep 1 2024, 12:12 PM
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.