2006-07-16 12:25:07 +04:00
|
|
|
.\" $NetBSD: kprintf.9,v 1.20 2006/07/16 08:25:07 rillig Exp $
|
1998-09-02 08:39:23 +04:00
|
|
|
.\"
|
2002-12-31 20:49:14 +03:00
|
|
|
.\" Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
|
1998-09-02 08:39:23 +04:00
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" This code is derived from software contributed to The NetBSD Foundation
|
2002-12-31 20:49:14 +03:00
|
|
|
.\" by Jeremy Cooper and by Jason R. Thorpe.
|
1998-09-02 08:39:23 +04:00
|
|
|
.\"
|
|
|
|
.\" 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.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the NetBSD
|
|
|
|
.\" Foundation, Inc. and its contributors.
|
|
|
|
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
.\" contributors may be used to endorse or promote products derived
|
|
|
|
.\" from this software without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
2001-09-04 06:51:15 +04:00
|
|
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
1998-09-02 08:39:23 +04:00
|
|
|
.\" 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.
|
|
|
|
.\"
|
2006-01-16 00:45:50 +03:00
|
|
|
.Dd January 15, 2006
|
1998-09-02 08:39:23 +04:00
|
|
|
.Dt KPRINTF 9
|
1999-03-16 03:40:46 +03:00
|
|
|
.Os
|
1998-09-02 08:39:23 +04:00
|
|
|
.Sh NAME
|
2000-08-09 07:12:33 +04:00
|
|
|
.Nm printf, snprintf, vprintf, vsnprintf, uprintf, ttyprintf, tprintf
|
1998-09-02 08:39:23 +04:00
|
|
|
.Nd kernel formatted output conversion
|
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In sys/systm.h
|
1998-09-02 08:39:23 +04:00
|
|
|
.Ft void
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn "printf" "const char *format" "..."
|
2003-01-01 02:53:09 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn "printf_nolog" "const char *format" "..."
|
1998-09-02 08:39:23 +04:00
|
|
|
.Ft int
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn "snprintf" "char *buf" "size_t size" "const char *format" "..."
|
1998-09-02 08:39:23 +04:00
|
|
|
.Ft void
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn "vprintf" "const char *format" "va_list ap"
|
|
|
|
.Ft int
|
|
|
|
.Fn "vsnprintf" "char *buf" "size_t size" "const char *format" "va_list ap"
|
|
|
|
.Ft void
|
|
|
|
.Fn "uprintf" "const char *format" "..."
|
1998-09-02 08:39:23 +04:00
|
|
|
.Ft void
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn "ttyprintf" "struct tty *tty" "const char *format" "..."
|
2003-04-16 17:34:34 +04:00
|
|
|
.In sys/tprintf.h
|
2000-08-09 07:12:33 +04:00
|
|
|
.Ft tpr_t
|
|
|
|
.Fn "tprintf_open" "struct proc *p"
|
1998-09-02 08:39:23 +04:00
|
|
|
.Ft void
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn "tprintf" "tpr_t tpr" "const char *format" "..."
|
|
|
|
.Ft void
|
|
|
|
.Fn "tprintf_close" "tpr_t tpr"
|
2002-12-31 20:49:14 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn "aprint_normal" "const char *format" "..."
|
|
|
|
.Ft void
|
|
|
|
.Fn "aprint_naive" "const char *format" "..."
|
|
|
|
.Ft void
|
|
|
|
.Fn "aprint_verbose" "const char *format" "..."
|
|
|
|
.Ft void
|
|
|
|
.Fn "aprint_debug" "const char *format" "..."
|
2003-01-01 02:53:09 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn "aprint_error" "const char *format" "..."
|
|
|
|
.Ft int
|
|
|
|
.Fn "aprint_get_error_count" "void"
|
1998-09-02 08:39:23 +04:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn printf
|
|
|
|
family of functions allows the kernel to send formatted messages to various
|
|
|
|
output devices.
|
1998-09-02 08:39:23 +04:00
|
|
|
The functions
|
|
|
|
.Fn printf
|
|
|
|
and
|
|
|
|
.Fn vprintf
|
|
|
|
send formatted strings to the system console.
|
2003-01-01 02:53:09 +03:00
|
|
|
The
|
|
|
|
.Fn printf_nolog
|
|
|
|
function is identical to
|
|
|
|
.Fn printf ,
|
|
|
|
except it does not send the data to the system log.
|
1998-09-02 08:39:23 +04:00
|
|
|
The functions
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn snprintf
|
|
|
|
and
|
|
|
|
.Fn vsnprintf
|
2002-10-14 17:43:14 +04:00
|
|
|
write output to a string buffer.
|
|
|
|
These four functions work similarly to their user space counterparts,
|
|
|
|
and are not described in detail here.
|
2000-08-09 07:12:33 +04:00
|
|
|
.Pp
|
|
|
|
The functions
|
1998-09-02 08:39:23 +04:00
|
|
|
.Fn uprintf
|
|
|
|
and
|
|
|
|
.Fn ttyprintf
|
|
|
|
send formatted strings to the current process's controlling tty and a specific
|
2000-08-09 07:12:33 +04:00
|
|
|
tty, respectively.
|
1998-09-02 08:39:23 +04:00
|
|
|
.Pp
|
2000-02-07 15:37:02 +03:00
|
|
|
The
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn tprintf
|
|
|
|
function sends formatted strings to a process's controlling tty,
|
|
|
|
via a handle of type tpr_t.
|
|
|
|
This allows multiple write operations to the tty with a guarantee that the
|
2002-10-14 17:43:14 +04:00
|
|
|
tty will be valid across calls.
|
|
|
|
A handle is acquired by calling
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn tprintf_open
|
2002-10-14 17:43:14 +04:00
|
|
|
with the target process as an argument.
|
|
|
|
This handle must be closed with a matching call to
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn tprintf_close .
|
2002-12-31 20:49:14 +03:00
|
|
|
.Pp
|
|
|
|
The functions
|
|
|
|
.Fn aprint_normal ,
|
|
|
|
.Fn aprint_naive ,
|
|
|
|
.Fn aprint_verbose ,
|
2003-01-01 02:53:09 +03:00
|
|
|
.Fn aprint_debug ,
|
2002-12-31 20:49:14 +03:00
|
|
|
and
|
2003-01-01 02:53:09 +03:00
|
|
|
.Fn aprint_error
|
2002-12-31 20:49:14 +03:00
|
|
|
are intended to be used to print autoconfiguration messages, and change
|
|
|
|
their behavior based on flags in the
|
|
|
|
.Dq boothowto
|
|
|
|
variable:
|
|
|
|
.Bl -tag -width "aprint_verbose()"
|
|
|
|
.It Fn aprint_normal
|
|
|
|
Sends to the console unless
|
|
|
|
.Dv AB_QUIET
|
2003-01-02 13:17:27 +03:00
|
|
|
is set.
|
|
|
|
Always sends to the log.
|
2002-12-31 20:49:14 +03:00
|
|
|
.It Fn aprint_naive
|
|
|
|
Sends to the console only if
|
|
|
|
.Dv AB_QUIET
|
2003-01-02 13:17:27 +03:00
|
|
|
is set.
|
|
|
|
Never sends to the log.
|
2002-12-31 20:49:14 +03:00
|
|
|
.It Fn aprint_verbose
|
|
|
|
Sends to the console only if
|
|
|
|
.Dv AB_VERBOSE
|
2003-01-02 13:17:27 +03:00
|
|
|
is set.
|
|
|
|
Always sends to the log.
|
2002-12-31 20:49:14 +03:00
|
|
|
.It Fn aprint_debug
|
|
|
|
Sends to the console and the log only if
|
|
|
|
.Dv AB_DEBUG
|
|
|
|
is set.
|
2003-01-01 02:53:09 +03:00
|
|
|
.It Fn aprint_error
|
|
|
|
Like
|
|
|
|
.Fn aprint_normal ,
|
|
|
|
but also keeps track of the number of times called.
|
|
|
|
This allows a subsystem to report the number of errors that occurred
|
|
|
|
during a quiet or silent initialization phase.
|
|
|
|
The
|
|
|
|
.Fn aprint_get_error_count
|
|
|
|
function reports the number of errors and resets the counter to 0.
|
2002-12-31 20:49:14 +03:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
If
|
|
|
|
.Dv AB_SILENT
|
|
|
|
is set, none of the autoconfiguration message printing routines send output
|
|
|
|
to the console.
|
|
|
|
The
|
|
|
|
.Dv AB_VERBOSE
|
|
|
|
and
|
|
|
|
.Dv AB_DEBUG
|
|
|
|
flags override
|
|
|
|
.Dv AB_SILENT .
|
1998-09-02 08:39:23 +04:00
|
|
|
.Sh RETURN VALUES
|
|
|
|
The
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn snprintf
|
|
|
|
and
|
|
|
|
.Fn vsnprintf
|
|
|
|
functions return the number of characters placed in the buffer
|
1998-09-02 08:39:23 +04:00
|
|
|
.Fa buf .
|
2006-07-16 12:25:07 +04:00
|
|
|
This is different to the user-space functions of the same name.
|
2006-01-14 16:08:18 +03:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn tprintf_open
|
|
|
|
function returns
|
|
|
|
.Dv NULL
|
|
|
|
if no terminal handle could be acquired.
|
1998-09-02 08:39:23 +04:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr printf 1 ,
|
2001-12-26 03:16:30 +03:00
|
|
|
.Xr printf 3 ,
|
2000-08-09 07:12:33 +04:00
|
|
|
.Xr bitmask_snprintf 9
|
1998-09-02 08:39:23 +04:00
|
|
|
.Sh CODE REFERENCES
|
|
|
|
.Pa sys/kern/subr_prf.c
|
2000-08-09 07:12:33 +04:00
|
|
|
.Sh HISTORY
|
1998-09-02 08:39:23 +04:00
|
|
|
The
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn sprintf
|
|
|
|
and
|
|
|
|
.Fn vsprintf
|
|
|
|
unsized string formatting functions are supported for compatibility only,
|
2002-10-14 17:43:14 +04:00
|
|
|
and are not documented here.
|
|
|
|
New code should use the size-limited
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn snprintf
|
|
|
|
and
|
|
|
|
.Fn vsnprintf
|
|
|
|
functions instead.
|
|
|
|
.Pp
|
|
|
|
In
|
|
|
|
.Nx 1.5
|
|
|
|
and earlier,
|
|
|
|
.Fn printf
|
|
|
|
supported more format strings than the user space
|
|
|
|
.Fn printf .
|
2002-10-14 17:43:14 +04:00
|
|
|
These nonstandard format strings are no longer supported.
|
|
|
|
For the functionality provided by the former
|
1998-09-02 08:39:23 +04:00
|
|
|
.Li %b
|
2000-08-09 07:12:33 +04:00
|
|
|
format string, see
|
|
|
|
.Xr bitmask_snprintf 9 .
|
2002-12-31 20:49:14 +03:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn aprint_normal ,
|
|
|
|
.Fn aprint_naive ,
|
|
|
|
.Fn aprint_verbose ,
|
|
|
|
and
|
|
|
|
.Fn aprint_debug
|
|
|
|
functions first appeared in
|
|
|
|
.Bsx .
|
2000-08-09 07:12:33 +04:00
|
|
|
.Sh BUGS
|
1998-09-02 08:39:23 +04:00
|
|
|
The
|
|
|
|
.Fn uprintf
|
|
|
|
and
|
|
|
|
.Fn ttyprintf
|
2002-10-14 17:43:14 +04:00
|
|
|
functions should be used sparingly, if at all.
|
|
|
|
Where multiple lines of output are required to reach a process's
|
|
|
|
controlling terminal,
|
2000-08-09 07:12:33 +04:00
|
|
|
.Fn tprintf
|
|
|
|
is preferred.
|