xref: /freebsd/share/man/man9/printf.9 (revision c17d43407fe04133a94055b0dbc7ea8965654a9f)
1.\"
2.\" Copyright (c) 2001 Andrew R. Reiter
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
21.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\"
28.Dd April 25, 2001
29.Dt PRINTF 9
30.Os
31.Sh NAME
32.Nm printf , uprintf , tprintf
33.Nd formatted output conversion
34.Sh SYNOPSIS
35.In sys/types.h
36.In sys/systm.h
37.Ft int
38.Fn printf "const char *fmt" "..."
39.Ft void
40.Fn tprintf "struct proc *p" "int pri" "const char *fmt" "..."
41.Ft int
42.Fn uprintf "const char *fmt" "..."
43.Sh DESCRIPTION
44The
45.Xr printf 9
46family of functions are similar to the
47.Xr printf 3
48family of functions.
49The three functions each use a different output stream.
50The
51.Fn uprintf
52function outputs to the current process' controlling tty, while
53.Fn printf
54writes to the console as well as to the logging facility.
55The
56.Fn tprintf
57function outputs to the tty associated with the process
58.Fa p
59and the logging facility if
60.Fa pri
61is not \&-1.
62.Pp
63Each of these related functions use the
64.Fa fmt
65parameter in the same manner as
66.Xr printf 3 .
67However,
68.Xr printf 9
69adds two other conversion specifiers.
70.Pp
71The
72.Cm \&%b
73identifier expects two arguments: an
74.Vt int
75and a
76.Vt "char *" .
77These are used as a register value and a print mask for decoding bitmasks.
78The print mask is made up of two parts: the base and the
79arguments.
80The base value is the output base expressed as an integer value;
81for example, \\10 gives octal and \\20 gives hexadecimal.
82The arguments are made up of a sequence of bit identifiers.
83Each bit identifier begins with an integer value which is the number of the
84bit this identifier describes.
85The rest of the identifier is a string of characters containing the name of
86the bit.
87The string is terminated by either the bit number at the start of the next
88bit identifier or
89.Dv NUL
90for the last bit identifier.
91.Pp
92The
93.Cm \&%D
94identifier is meant to assist in hexdumps.
95It requires two arguments: a
96.Vt "u_char *"
97pointer and a
98.Vt "char *"
99string.
100The memory pointed to be the pointer is output in hexadecimal one byte at
101a time.
102The string is used as a delimiter between individual bytes.
103If present, a width directive will specify the number of bytes to display.
104By default, 16 bytes of data are output.
105.Sh RETURN VALUES
106The
107.Fn printf
108and the
109.Fn uprintf
110functions return the number of characters displayed.
111.Sh EXAMPLES
112This example demonstrates the use of the \&%b and \&%D conversion specifiers.
113The function
114.Bd -literal -offset indent
115void
116printf_test(void)
117{
118
119	printf("reg=%b\\n", 3, "\\10\\2BITTWO\\1BITONE\\n");
120	printf("out: %4D\\n", "AAAA", ":");
121}
122.Ed
123.Pp
124will produce the following output:
125.Bd -literal -offset indent
126reg=3<BITTWO,BITONE>
127out: 41:41:41:41
128.Ed
129.Sh SEE ALSO
130.Xr printf 3
131