vprintf(3S) vprintf(3S)
NAME
vprintf, vfprintf, vsprintf, vwprintf, vfwprintf, vswprintf - print
formatted output of a variable argument list
SYNOPSIS
#include <stdio.h>
#include <stdarg.h>
#include <wchar.h>
int vprintf(const char *format, valist ap);
int vfprintf(FILE *stream, const char *format, valist ap);
int vsprintf(char *s, const char *format, valist ap);
int vwprintf(const wchart *format, valist ap);
int vfwprintf(FILE *stream, const wchart *format, valist ap);
int vswprintf(wchart *s, sizet n, const wchart *format, valist ap);
DESCRIPTION
vprintf(), vfprintf() and vsprintf() are the same as printf(),
fprintf(), and sprintf() respectively, except that instead of being
called with a variable number of arguments, they are called with an
argument list as defined by the stdarg.h header file.
The functions vwprintf(), vfwprintf(), and vswprintf() are equivalent
to the functions swprintf(), fwprintf(), and swprintf() respectively,
with the variable argument list replaced by ap, which shall have been
initialized by the vastart macro (and possibly subsequent vaarg
calls). These functions do not invoke the vaend macro.
As the functions vfwprintf(), vswprintf(), and vwprintf() invoke the
vaarg macro, the value of ap after the return is unspecified.
The stdarg.h header file defines the type valist and a set of macros
for advancing through a list of arguments whose number and types may
vary. The argument ap is of type valist. This argument is used with
the stdarg.h header file macros vastart, vaarg and vaend [see
stdarg(5)].
EXAMPLES
The following code fragment illustrates the use of vfprintf() to write
an error routine:
#include <stdio.h>
#include <stdarg.h>
/*
* error should be called like
* error(functionname, format, arg1, ...);
*/
Page 1 Reliant UNIX 5.44 Printed 11/98
vprintf(3S) vprintf(3S)
void error(char *functionname, char *format, ...)
{
valist ap;
vastart(ap, format);
/* print out name of function causing error */
(void) fprintf(stderr, "ERR in %s: ", functionname);
vaarg(ap, char*);
/* print out remainder of message */
(void) vfprintf(stderr, format, ap);
vaend(ap);
(void) abort;
}
The following show the use of the vfwprintf() function in a general
error-reporting routine.
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
void error(char *functionname, wchart *format, ...)
{
valist ap;
vastart(ap, format);
/* print out name of function causing error */
fwprintf(stderr, L"ERROR in %s: ", functionname);
/* print out remainder of message */
vfwprintf(stderr, format, ap);
vaend(ap);
}
ERRORS
The following error code descriptions are function-specific. You will
find a general description in introprm2(2) or in errno(5).
These functions will fail if either the stream is unbuffered or the
stream's buffer needed to be flushed and:
EAGAIN The ONONBLOCK flag is set for the file descriptor underly-
ing stream and the process would be delayed in the write
operation.
EBADF The file descriptor underlying stream is not a valid file
descriptor open for writing.
EFBIG An attempt was made to write to a file that exceeds the max-
imum file size or the process' file size limit.
Page 2 Reliant UNIX 5.44 Printed 11/98
vprintf(3S) vprintf(3S)
EFBIG The file is a regular file and an attempt was made to write
at or beyond the offset maximum associated with the corres-
ponding stream.
EINTR The write operation was terminated due to the receipt of a
signal, and no data was transferred.
EIO A physical I/O error has occurred, or the process is a
member of a background process group attempting to write to
its controlling terminal, TOSTOP is set, the process is nei-
ther ignoring nor blocking SIGTTOU and the process group of
the process is orphaned. This error may also be returned
under implementation-dependent conditions.
ENOSPC There was no free space remaining on the device containing
the file.
EPIPE An attempt is made to write to a pipe or FIFO that is not
open for reading by any process. A SIGPIPE signal will also
be sent to the process.
The function may fail if:
EILSEQ A wide-character code that does not correspond to a valid
character has been detected.
EINVAL There are insufficient arguments.
ENOMEM Insufficient storage space is available.
ENXIO A request was made of a non-existent device, or the request
was outside the capabilities of the device.
RETURN VALUES
vprintf() and vfprintf() return the number of characters transmitted,
or return -1 if an error was encountered.
The vwprintf() and the vfwprintf() functions return the number of
wide-characters transmitted, or a negative value if an output error
occurred.
The vswprintf() function returns the number of wide-characters written
in the array, not counting the terminating null wide-character, or a
negative value if n or more wide-characters were requested to be gen-
erated.
NOTES
After using these functions you should call the vaend(ap) macro to
reset the pointer ap to a defined value so that any subsequent calls
to these functions have correct initial values.
Page 3 Reliant UNIX 5.44 Printed 11/98
vprintf(3S) vprintf(3S)
SEE ALSO
printf(3S), lfs(5), stdarg(5), stdio(5), wchar(5).
Page 4 Reliant UNIX 5.44 Printed 11/98