2 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved.
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/.
6 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text
7 .\" are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical
8 .\" and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
9 .\" This notice shall appear on any product containing this material.
10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
11 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
12 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
13 .TH VPRINTF 3C "Jan 7, 2009"
15 vprintf, vfprintf, vsprintf, vsnprintf, vasprintf \- print formatted output of
16 a variable argument list
23 \fBint\fR \fBvprintf\fR(\fBconst char *\fR\fIformat\fR, \fBva_list\fR \fIap\fR);
28 \fBint\fR \fBvfprintf\fR(\fBFILE *\fR\fIstream\fR, \fBconst char *\fR\fIformat\fR, \fBva_list\fR \fIap\fR);
33 \fBint\fR \fBvsprintf\fR(\fBchar *\fR\fIs\fR, \fBconst char *\fR\fIformat\fR, \fBva_list\fR \fIap\fR);
38 \fBint\fR \fBvsnprintf\fR(\fBchar *\fR\fIs\fR, \fBsize_t\fR \fIn\fR, \fBconst char *\fR\fIformat\fR, \fBva_list\fR \fIap\fR);
43 \fBint\fR \fBvasprintf\fR(\fBchar **\fR\fIret\fR, \fBconst char *\fR\fIformat\fR, \fBva_list\fR \fIap\fR);
49 The \fBvprintf()\fR, \fBvfprintf()\fR, \fBvsprintf()\fR, \fBvsnprintf()\fR, and
50 \fBvasprintf()\fR functions are the same as \fBprintf()\fR, \fBfprintf()\fR,
51 \fBsprintf()\fR, \fBsnprintf()\fR, and \fBasprintf()\fR, respectively, except
52 that instead of being called with a variable number of arguments, they are
53 called with an argument list as defined in the \fB<stdarg.h>\fR header. See
57 The \fB<stdarg.h>\fR header defines the type \fBva_list\fR and a set of macros
58 for advancing through a list of arguments whose number and types may vary. The
59 argument \fIap\fR to the \fBvprint\fR family of functions is of type
60 \fBva_list\fR. This argument is used with the <\fBstdarg.h\fR> header file
61 macros \fBva_start()\fR, \fBva_arg()\fR, and \fBva_end()\fR (see
62 \fBstdarg\fR(3EXT)). The \fBEXAMPLES\fR section below demonstrates the use of
63 \fBva_start()\fR and \fBva_end()\fR with \fBvprintf()\fR.
66 The macro \fBva_alist()\fR is used as the parameter list in a function
67 definition, as in the function called \fBerror()\fR in the example below. The
68 macro \fBva_start(\fR\fIap, name\fR\fB),\fR where \fIap\fR is of type
69 \fBva_list\fR and \fIname\fR is the rightmost parameter (just before
70 \|.\|.\|.), must be called before any attempt to traverse and access unnamed
71 arguments is made. The \fBva_end(\fR\fIap\fR\fB)\fR macro must be invoked when
72 all desired arguments have been accessed. The argument list in \fIap\fR can be
73 traversed again if \fBva_start()\fR is called again after \fBva_end()\fR. In
74 the example below, the \fBerror()\fR arguments (\fIarg1\fR, \fIarg2\fR,
75 \&.\|.\|.) are passed to \fBvfprintf()\fR in the argument \fIap\fR.
79 Refer to \fBprintf\fR(3C).
83 The \fBvprintf()\fR and \fBvfprintf()\fR functions will fail if either the
84 \fIstream\fR is unbuffered or the \fIstream\fR's buffer needed to be flushed
92 The file is a regular file and an attempt was made to write at or beyond the
98 \fBExample 1 \fRUsing \fBvprintf()\fR to write an error routine.
101 The following demonstrates how \fBvfprintf()\fR could be used to write an error
111 * error should be called like
112 * error(function_name, format, arg1, \&.\|.\|.);
114 void error(char *function_name, char *format, \&.\|.\|.)
117 va_start(ap, format);
118 /* print out name of function causing error */
119 (void) fprintf(stderr, "ERR in %s: ", function_name);
120 /* print out remainder of message */
121 (void) vfprintf(stderr, format, ap);
131 See \fBattributes\fR(5) for descriptions of the following attributes:
139 ATTRIBUTE TYPE ATTRIBUTE VALUE
141 Interface Stability Committed
150 All of these functions can be used safely in multithreaded applications, as
151 long as \fBsetlocale\fR(3C) is not being called to change the locale.
154 See \fBstandards\fR(5) for the standards conformance of \fBvprintf()\fR,
155 \fBvfprintf()\fR, \fBvsprintf()\fR, and \fBvsnprintf()\fR. The
156 \fBvasprintf()\fR function is modeled on the one that appears in the FreeBSD,
157 NetBSD, and GNU C libraries.
161 \fBprintf\fR(3C), \fBattributes\fR(5), \fBstdarg\fR(3EXT), \fBattributes\fR(5),
166 The \fBvsnprintf()\fR return value when \fIn\fR = 0 was changed in the Solaris
167 10 release. The change was based on the SUSv3 specification. The previous
168 behavior was based on the initial SUSv2 specification, where \fBvsnprintf()\fR
169 when \fIn\fR = 0 returns an unspecified value less than 1.