xref: /netbsd/share/man/man9/kprintf.9 (revision bf9ec67e)
1.\"     $NetBSD: kprintf.9,v 1.12 2002/02/13 08:18:43 ross Exp $
2.\"
3.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jeremy Cooper.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd September 1, 1998
38.Dt KPRINTF 9
39.Os
40.Sh NAME
41.Nm printf, snprintf, vprintf, vsnprintf, uprintf, ttyprintf, tprintf
42.Nd kernel formatted output conversion
43.Sh SYNOPSIS
44.Fd #include \*[Lt]sys/systm.h\*[Gt]
45.Ft void
46.Fn "printf" "const char *format" "..."
47.Ft int
48.Fn "snprintf" "char *buf" "size_t size" "const char *format" "..."
49.Ft void
50.Fn "vprintf" "const char *format" "va_list ap"
51.Ft int
52.Fn "vsnprintf" "char *buf" "size_t size" "const char *format" "va_list ap"
53.Ft void
54.Fn "uprintf" "const char *format" "..."
55.Ft void
56.Fn "ttyprintf" "struct tty *tty" "const char *format" "..."
57.Fd #include \*[Lt]sys/tprintf.h\*[Gt]
58.Ft tpr_t
59.Fn "tprintf_open" "struct proc *p"
60.Ft void
61.Fn "tprintf" "tpr_t tpr" "const char *format" "..."
62.Ft void
63.Fn "tprintf_close" "tpr_t tpr"
64.Sh DESCRIPTION
65The
66.Fn printf
67family of functions allows the kernel to send formatted messages to various
68output devices.
69The functions
70.Fn printf
71and
72.Fn vprintf
73send formatted strings to the system console.
74The functions
75.Fn snprintf
76and
77.Fn vsnprintf
78write output to a string buffer.  These four functions work similarly
79to their user space counterparts, and are not described in detail here.
80.Pp
81The functions
82.Fn uprintf
83and
84.Fn ttyprintf
85send formatted strings to the current process's controlling tty and a specific
86tty, respectively.
87.Pp
88The
89.Fn tprintf
90function sends formatted strings to a process's controlling tty,
91via a handle of type tpr_t.
92This allows multiple write operations to the tty with a guarantee that the
93tty will be valid across calls.  A handle is acquired by calling
94.Fn tprintf_open
95with the target process as an argument.  This handle must be closed with
96a matching call to
97.Fn tprintf_close .
98.Sh RETURN VALUES
99The
100.Fn snprintf
101and
102.Fn vsnprintf
103functions return the number of characters placed in the buffer
104.Fa buf .
105.Sh SEE ALSO
106.Xr printf 1 ,
107.Xr printf 3 ,
108.Xr bitmask_snprintf 9
109.Sh CODE REFERENCES
110.Pa sys/kern/subr_prf.c
111.Sh HISTORY
112The
113.Fn sprintf
114and
115.Fn vsprintf
116unsized string formatting functions are supported for compatibility only,
117and are not documented here.  New code should use the size-limited
118.Fn snprintf
119and
120.Fn vsnprintf
121functions instead.
122.Pp
123In
124.Nx 1.5
125and earlier,
126.Fn printf
127supported more format strings than the user space
128.Fn printf .
129These nonstandard format strings are no longer supported.  For the
130functionality provided by the former
131.Li %b
132format string, see
133.Xr bitmask_snprintf 9 .
134.Sh BUGS
135The
136.Fn uprintf
137and
138.Fn ttyprintf
139functions should be used sparingly, if at all.  Where multiple lines of
140output are required to reach a process's controlling terminal,
141.Fn tprintf
142is preferred.
143