|
BITMASK_SNPRINTF(9)
Contents
|
bitmask_snprintf - bitmask output conversion
#include <sys/systm.h>
void
bitmask_snprintf(u_quad_t val, const char *fmt, char *buf,
size_t buflen);
The bitmask_snprintf() function formats a bitmask into a mnemonic form
suitable for printing.
This conversion is useful for decoding bit fields in device registers.
It formats the integer val into the buffer buf, of size buflen, using a
specified radix and an interpretation of the bits within that integer as
though they were flags.
The decoding directive string fmt describes how the bitfield is to be
interpreted and displayed. The first character of fmt is a binary character
representation of the output numeral base in which the bitfield
will be printed before it is decoded. Recognized radix values (in C
escape-character format) are \10 (octal), \12 (decimal), and \20
(hexadecimal).
The remaining characters in fmt are interpreted as a list of bit-position-description
pairs. A bit-position-description pair begins with a
binary character value that represents the position of the bit being
described. A bit position value of one describes the least significant
bit. Whereas a position value of 32 (octal 40, hexadecimal 20, the ASCII
space character) describes the most significant bit.
The remaining characters in a bit-position-description pair are the characters
to print should the bit being described be set. Description
strings are delimited by the next bit position value character encountered
(distinguishable by its value being <= 32), or the end of the
decoding directive string itself.
The bitmask_snprintf() function returns the buffer buf. The returned
string is always NULL-terminated.
Two examples of the old formatting style:
bitmask_snprintf(3, "\10\2BITTWO\1BITONE", buf, buflen)
=> "3<BITTWO,BITONE>"
bitmask_snprintf(0xe860,
"\20\x10NOTBOOT\x0fFPP\x0eSDVMA\x0cVIDEO"
"\x0bLORES\x0aFPA\x09DIAG\x07CACHE"
"\x06IOCACHE\x05LOOPBACK\x04DBGCACHE",
buf, buflen)
=> "e860<NOTBOOT,FPP,SDVMA,VIDEO,CACHE,IOCACHE>"
If the buffer buf is too small to hold the formatted output,
bitmask_snprintf() will still return the buffer, containing a truncated
string.
printf(9)
sys/kern/subr_prf.c
The bitmask_snprintf() function was originally implemented as a non-standard
%b format string for the kernel printf() function in NetBSD 1.5 and
earlier releases.
bitmask_snprintf() supports a new extended form of formatting string,
which is not yet described here.
BSD July 28, 2000 BSD
[ Back ] |