2001-05-04 23:25:58 +00:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 2001 Andrew R. Reiter
|
2005-07-31 03:30:48 +00:00
|
|
|
.\" Copyright (c) 2004 Joerg Wunsch
|
2001-05-04 23:25:58 +00:00
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2004-08-10 09:19:08 +00:00
|
|
|
.Dd August 10, 2004
|
2001-05-04 23:25:58 +00:00
|
|
|
.Dt PRINTF 9
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
2004-08-10 09:19:08 +00:00
|
|
|
.Nm printf , uprintf , tprintf, log
|
2001-05-04 23:25:58 +00:00
|
|
|
.Nd formatted output conversion
|
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In sys/types.h
|
|
|
|
.In sys/systm.h
|
2001-05-04 23:25:58 +00:00
|
|
|
.Ft int
|
2005-01-12 21:48:25 +00:00
|
|
|
.Fn printf "const char *fmt" ...
|
2001-05-04 23:25:58 +00:00
|
|
|
.Ft void
|
2005-01-12 21:48:25 +00:00
|
|
|
.Fn tprintf "struct proc *p" "int pri" "const char *fmt" ...
|
2001-05-04 23:25:58 +00:00
|
|
|
.Ft int
|
2005-01-12 21:48:25 +00:00
|
|
|
.Fn uprintf "const char *fmt" ...
|
2005-01-20 10:26:42 +00:00
|
|
|
.In sys/syslog.h
|
2004-08-10 09:19:08 +00:00
|
|
|
.Ft void
|
2005-01-12 21:48:25 +00:00
|
|
|
.Fn log "int pri" "const char *fmt" ...
|
2001-05-04 23:25:58 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Xr printf 9
|
|
|
|
family of functions are similar to the
|
|
|
|
.Xr printf 3
|
|
|
|
family of functions.
|
2004-08-10 09:19:08 +00:00
|
|
|
The different functions each use a different output stream.
|
2001-05-04 23:25:58 +00:00
|
|
|
The
|
|
|
|
.Fn uprintf
|
2001-05-07 12:48:38 +00:00
|
|
|
function outputs to the current process' controlling tty, while
|
2001-05-04 23:25:58 +00:00
|
|
|
.Fn printf
|
2001-05-07 12:48:38 +00:00
|
|
|
writes to the console as well as to the logging facility.
|
2001-05-04 23:25:58 +00:00
|
|
|
The
|
|
|
|
.Fn tprintf
|
|
|
|
function outputs to the tty associated with the process
|
|
|
|
.Fa p
|
|
|
|
and the logging facility if
|
|
|
|
.Fa pri
|
2005-01-12 21:48:25 +00:00
|
|
|
is not \-1.
|
2004-08-10 09:19:08 +00:00
|
|
|
The
|
|
|
|
.Fn log
|
|
|
|
function sends the message to the kernel logging facility, using
|
|
|
|
the log level as indicated by
|
|
|
|
.Fa pri .
|
2001-05-07 12:48:38 +00:00
|
|
|
.Pp
|
|
|
|
Each of these related functions use the
|
2001-05-04 23:25:58 +00:00
|
|
|
.Fa fmt
|
|
|
|
parameter in the same manner as
|
|
|
|
.Xr printf 3 .
|
|
|
|
However,
|
|
|
|
.Xr printf 9
|
|
|
|
adds two other conversion specifiers.
|
|
|
|
.Pp
|
2001-05-07 12:48:38 +00:00
|
|
|
The
|
|
|
|
.Cm \&%b
|
2001-05-04 23:25:58 +00:00
|
|
|
identifier expects two arguments: an
|
2001-05-07 12:48:38 +00:00
|
|
|
.Vt int
|
2001-05-04 23:25:58 +00:00
|
|
|
and a
|
2001-05-07 12:48:38 +00:00
|
|
|
.Vt "char *" .
|
2001-05-04 23:25:58 +00:00
|
|
|
These are used as a register value and a print mask for decoding bitmasks.
|
2001-05-07 12:48:38 +00:00
|
|
|
The print mask is made up of two parts: the base and the
|
2001-05-04 23:25:58 +00:00
|
|
|
arguments.
|
|
|
|
The base value is the output base expressed as an integer value;
|
2005-01-12 21:48:25 +00:00
|
|
|
for example, \e10 gives octal and \e20 gives hexadecimal.
|
2001-05-04 23:25:58 +00:00
|
|
|
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 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
|
2001-05-07 12:48:38 +00:00
|
|
|
bit identifier or
|
|
|
|
.Dv NUL
|
|
|
|
for the last bit identifier.
|
2001-05-04 23:25:58 +00:00
|
|
|
.Pp
|
2001-05-07 12:48:38 +00:00
|
|
|
The
|
2001-05-04 23:25:58 +00:00
|
|
|
.Cm \&%D
|
|
|
|
identifier is meant to assist in hexdumps.
|
|
|
|
It requires two arguments: a
|
2001-05-07 12:48:38 +00:00
|
|
|
.Vt "u_char *"
|
2001-05-04 23:25:58 +00:00
|
|
|
pointer and a
|
2001-05-07 12:48:38 +00:00
|
|
|
.Vt "char *"
|
2001-05-04 23:25:58 +00:00
|
|
|
string.
|
|
|
|
The memory pointed to be 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.
|
2004-08-10 09:19:08 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn log
|
|
|
|
function uses
|
|
|
|
.Xr syslog 3
|
|
|
|
level values
|
|
|
|
.Dv LOG_DEBUG
|
|
|
|
through
|
|
|
|
.Dv LOG_EMERG
|
|
|
|
for its
|
|
|
|
.Fa pri
|
|
|
|
parameter (mistakenly called
|
|
|
|
.Sq priority
|
|
|
|
here).
|
|
|
|
Alternatively, if a
|
|
|
|
.Fa pri
|
2005-01-12 21:48:25 +00:00
|
|
|
of \-1 is given, the message will be appended to the last log message
|
2004-08-10 09:19:08 +00:00
|
|
|
started by a previous call to
|
|
|
|
.Fn log .
|
|
|
|
As these messages are generated by the kernel itself, the facility will
|
|
|
|
always be
|
|
|
|
.Dv LOG_KERN .
|
2001-05-04 23:25:58 +00:00
|
|
|
.Sh RETURN VALUES
|
|
|
|
The
|
|
|
|
.Fn printf
|
|
|
|
and the
|
|
|
|
.Fn uprintf
|
|
|
|
functions return the number of characters displayed.
|
|
|
|
.Sh EXAMPLES
|
|
|
|
This example demonstrates the use of the \&%b and \&%D conversion specifiers.
|
|
|
|
The function
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
void
|
|
|
|
printf_test(void)
|
|
|
|
{
|
|
|
|
|
2005-01-12 21:48:25 +00:00
|
|
|
printf("reg=%b\en", 3, "\e10\e2BITTWO\e1BITONE\en");
|
|
|
|
printf("out: %4D\en", "AAAA", ":");
|
2001-05-04 23:25:58 +00:00
|
|
|
}
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
will produce the following output:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
reg=3<BITTWO,BITONE>
|
|
|
|
out: 41:41:41:41
|
|
|
|
.Ed
|
2004-08-10 09:19:08 +00:00
|
|
|
.Pp
|
|
|
|
The call
|
|
|
|
.Bd -literal -offset indent
|
2005-01-12 21:48:25 +00:00
|
|
|
log(LOG_DEBUG, "%s%d: been there.\en", sc->sc_name, sc->sc_unit);
|
2004-08-10 09:19:08 +00:00
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
will add the appropriate debug message at priority
|
2005-01-12 21:48:25 +00:00
|
|
|
.Dq Li kern.debug
|
2004-08-10 09:19:08 +00:00
|
|
|
to the system log.
|
2001-05-04 23:25:58 +00:00
|
|
|
.Sh SEE ALSO
|
2004-08-10 09:19:08 +00:00
|
|
|
.Xr printf 3 ,
|
|
|
|
.Xr syslog 3
|