1.\" $NetBSD: kprintf.9,v 1.13 2002/10/14 13:43:25 wiz 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. 79These four functions work similarly to their user space counterparts, 80and are not described in detail here. 81.Pp 82The functions 83.Fn uprintf 84and 85.Fn ttyprintf 86send formatted strings to the current process's controlling tty and a specific 87tty, respectively. 88.Pp 89The 90.Fn tprintf 91function sends formatted strings to a process's controlling tty, 92via a handle of type tpr_t. 93This allows multiple write operations to the tty with a guarantee that the 94tty will be valid across calls. 95A handle is acquired by calling 96.Fn tprintf_open 97with the target process as an argument. 98This handle must be closed with a matching call to 99.Fn tprintf_close . 100.Sh RETURN VALUES 101The 102.Fn snprintf 103and 104.Fn vsnprintf 105functions return the number of characters placed in the buffer 106.Fa buf . 107.Sh SEE ALSO 108.Xr printf 1 , 109.Xr printf 3 , 110.Xr bitmask_snprintf 9 111.Sh CODE REFERENCES 112.Pa sys/kern/subr_prf.c 113.Sh HISTORY 114The 115.Fn sprintf 116and 117.Fn vsprintf 118unsized string formatting functions are supported for compatibility only, 119and are not documented here. 120New code should use the size-limited 121.Fn snprintf 122and 123.Fn vsnprintf 124functions instead. 125.Pp 126In 127.Nx 1.5 128and earlier, 129.Fn printf 130supported more format strings than the user space 131.Fn printf . 132These nonstandard format strings are no longer supported. 133For the functionality provided by the former 134.Li %b 135format string, see 136.Xr bitmask_snprintf 9 . 137.Sh BUGS 138The 139.Fn uprintf 140and 141.Fn ttyprintf 142functions should be used sparingly, if at all. 143Where multiple lines of output are required to reach a process's 144controlling terminal, 145.Fn tprintf 146is preferred. 147