Main index | Section 9 | 日本語 | Options |
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/syslog.h>
Each of these related functions use the fmt parameter in the same manner as printf(3). However, printf(9) adds two other conversion specifiers.
The amp;%b identifier expects two arguments: an int and a char *. These are used as a register value and a print mask for decoding bitmasks. The print mask is made up of two parts: the base and the arguments. The base value is the output base expressed as an integer value; for example, \10 gives octal and \20 gives hexadecimal. The arguments are made up of a sequence of bit identifiers. Each bit identifier begins with an integer value which is the number of the bit (starting from 1) this identifier describes. The rest of the identifier is a string of characters containing the name of the bit. The string is terminated by either the bit number at the start of the next bit identifier or NUL for the last bit identifier.
The amp;%D identifier is meant to assist in hexdumps. It requires two arguments: a u_char * pointer and a char * string. The memory pointed to by the pointer is output in hexadecimal one byte at a time. The string is used as a delimiter between individual bytes. If present, a width directive will specify the number of bytes to display. By default, 16 bytes of data are output.
The log() function uses syslog(3) level values LOG_DEBUG through LOG_EMERG for its pri parameter (mistakenly called 'priority' here). Alternatively, if a pri of -1 is given, the message will be appended to the last log message started by a previous call to log(). As these messages are generated by the kernel itself, the facility will always be LOG_KERN.
void printf_test(void) {printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE"); printf("out: %4D\n", "AAAA", ":"); }
will produce the following output:
reg=3<BITTWO,BITONE> out: 41:41:41:41
The call
log(LOG_DEBUG, "%s%d: been there.\n", sc->sc_name, sc->sc_unit);
will add the appropriate debug message at priority "kern.debug" to the system log.
PRINTF (9) | November 18, 2015 |
Main index | Section 9 | 日本語 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | The wonderful thing about standards is that there are so many of them to choose from. | ” |
— Grace Murray Hopper |