]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - share/man/man9/printf.9
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / share / man / man9 / printf.9
1 .\"
2 .\" Copyright (c) 2001 Andrew R. Reiter
3 .\" Copyright (c) 2004 Joerg Wunsch
4 .\" All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\"
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 .\" SUCH DAMAGE.
26 .\"
27 .\" $FreeBSD$
28 .\"
29 .Dd September 8, 2006
30 .Dt PRINTF 9
31 .Os
32 .Sh NAME
33 .Nm printf , uprintf , tprintf, log
34 .Nd formatted output conversion
35 .Sh SYNOPSIS
36 .In sys/types.h
37 .In sys/systm.h
38 .Ft int
39 .Fn printf "const char *fmt" ...
40 .Ft void
41 .Fn tprintf "struct proc *p" "int pri" "const char *fmt" ...
42 .Ft int
43 .Fn uprintf "const char *fmt" ...
44 .In sys/syslog.h
45 .Ft void
46 .Fn log "int pri" "const char *fmt" ...
47 .Sh DESCRIPTION
48 The
49 .Xr printf 9
50 family of functions are similar to the
51 .Xr printf 3
52 family of functions.
53 The different functions each use a different output stream.
54 The
55 .Fn uprintf
56 function outputs to the current process' controlling tty, while
57 .Fn printf
58 writes to the console as well as to the logging facility.
59 The
60 .Fn tprintf
61 function outputs to the tty associated with the process
62 .Fa p
63 and the logging facility if
64 .Fa pri
65 is not \-1.
66 The
67 .Fn log
68 function sends the message to the kernel logging facility, using
69 the log level as indicated by
70 .Fa pri .
71 .Pp
72 Each of these related functions use the
73 .Fa fmt
74 parameter in the same manner as
75 .Xr printf 3 .
76 However,
77 .Xr printf 9
78 adds two other conversion specifiers.
79 .Pp
80 The
81 .Cm \&%b
82 identifier expects two arguments: an
83 .Vt int
84 and a
85 .Vt "char *" .
86 These are used as a register value and a print mask for decoding bitmasks.
87 The print mask is made up of two parts: the base and the
88 arguments.
89 The base value is the output base expressed as an integer value;
90 for example, \e10 gives octal and \e20 gives hexadecimal.
91 The arguments are made up of a sequence of bit identifiers.
92 Each bit identifier begins with an integer value which is the number of the
93 bit (starting from 1) this identifier describes.
94 The rest of the identifier is a string of characters containing the name of
95 the bit.
96 The string is terminated by either the bit number at the start of the next
97 bit identifier or
98 .Dv NUL
99 for the last bit identifier.
100 .Pp
101 The
102 .Cm \&%D
103 identifier is meant to assist in hexdumps.
104 It requires two arguments: a
105 .Vt "u_char *"
106 pointer and a
107 .Vt "char *"
108 string.
109 The memory pointed to be the pointer is output in hexadecimal one byte at
110 a time.
111 The string is used as a delimiter between individual bytes.
112 If present, a width directive will specify the number of bytes to display.
113 By default, 16 bytes of data are output.
114 .Pp
115 The
116 .Fn log
117 function uses
118 .Xr syslog 3
119 level values
120 .Dv LOG_DEBUG
121 through
122 .Dv LOG_EMERG
123 for its
124 .Fa pri
125 parameter (mistakenly called
126 .Sq priority
127 here).
128 Alternatively, if a
129 .Fa pri
130 of \-1 is given, the message will be appended to the last log message
131 started by a previous call to
132 .Fn log .
133 As these messages are generated by the kernel itself, the facility will
134 always be
135 .Dv LOG_KERN .
136 .Sh RETURN VALUES
137 The
138 .Fn printf
139 and the
140 .Fn uprintf
141 functions return the number of characters displayed.
142 .Sh EXAMPLES
143 This example demonstrates the use of the
144 .Cm \&%b
145 and
146 .Cm \&%D
147 conversion specifiers.
148 The function
149 .Bd -literal -offset indent
150 void
151 printf_test(void)
152 {
153
154         printf("reg=%b\en", 3, "\e10\e2BITTWO\e1BITONE\en");
155         printf("out: %4D\en", "AAAA", ":");
156 }
157 .Ed
158 .Pp
159 will produce the following output:
160 .Bd -literal -offset indent
161 reg=3<BITTWO,BITONE>
162 out: 41:41:41:41
163 .Ed
164 .Pp
165 The call
166 .Bd -literal -offset indent
167 log(LOG_DEBUG, "%s%d: been there.\en", sc->sc_name, sc->sc_unit);
168 .Ed
169 .Pp
170 will add the appropriate debug message at priority
171 .Dq Li kern.debug
172 to the system log.
173 .Sh SEE ALSO
174 .Xr printf 3 ,
175 .Xr syslog 3