1vprintf(3C)              Standard C Library Functions              vprintf(3C)
2
3
4

NAME

6       vprintf,  vfprintf,  vsprintf,  vsnprintf,  vasprintf - print formatted
7       output of a variable argument list
8

SYNOPSIS

10       #include <stdio.h>
11       #include <stdarg.h>
12
13       int vprintf(const char *format, va_list ap);
14
15
16       int vfprintf(FILE *stream, const char *format, va_list ap);
17
18
19       int vsprintf(char *s, const char *format, va_list ap);
20
21
22       int vsnprintf(char *s, size_t n, const char *format, va_list ap);
23
24
25       int vasprintf(char **ret, const char *format, va_list ap);
26
27

DESCRIPTION

29       The vprintf(), vfprintf(),  vsprintf(),  vsnprintf(),  and  vasprintf()
30       functions  are  the same as printf(), fprintf(), sprintf(), snprintf(),
31       and asprintf(), respectively, except that instead of being called  with
32       a  variable  number of arguments, they are called with an argument list
33       as defined in the <stdarg.h> header. See printf(3C).
34
35
36       The <stdarg.h> header defines the type va_list and a set of macros  for
37       advancing  through a list of arguments whose number and types may vary.
38       The argument ap to the vprint family of functions is of  type  va_list.
39       This   argument   is  used  with  the  <stdarg.h>  header  file  macros
40       va_start(), va_arg(), and va_end()  (see  stdarg(3EXT)).  The  EXAMPLES
41       section  below  demonstrates  the  use  of va_start() and va_end() with
42       vprintf().
43
44
45       The macro va_alist() is used as the parameter list in a function  defi‐
46       nition,  as  in  the  function called error() in the example below. The
47       macro va_start(ap, name), where ap is of type va_list and name  is  the
48       rightmost  parameter  (just  before  ...),  must  be  called before any
49       attempt  to  traverse  and  access  unnamed  arguments  is  made.   The
50       va_end(ap)  macro  must be invoked when all desired arguments have been
51       accessed. The argument list in ap can be traversed again if  va_start()
52       is called again after va_end(). In the example below, the error() argu‐
53       ments (arg1, arg2, ...) are passed to vfprintf() in the argument ap.
54

RETURN VALUES

56       Refer to printf(3C).
57

ERRORS

59       The vprintf() and vfprintf() functions will fail if either  the  stream
60       is unbuffered or the stream's buffer needed to be flushed and:
61
62       EFBIG    The file is a regular file and an attempt was made to write at
63                or beyond the offset maximum.
64
65

EXAMPLES

67       Example 1 Using vprintf() to write an error routine.
68
69
70       The following demonstrates how vfprintf() could be  used  to  write  an
71       error routine:
72
73
74         #include <stdio.h>
75         #include <stdarg.h>
76         . . .
77         /*
78          *   error should be called like
79          *         error(function_name, format, arg1, ...);
80          */
81         void error(char *function_name, char *format, ...)
82         {
83                 va_list ap;
84                 va_start(ap, format);
85                 /* print out name of function causing error */
86                 (void) fprintf(stderr, "ERR in %s: ", function_name);
87                 /* print out remainder of message */
88                 (void) vfprintf(stderr, format, ap);
89                 va_end(ap);
90                 (void) abort();
91         }
92
93

ATTRIBUTES

95       See attributes(5) for descriptions of the following attributes:
96
97
98
99
100       ┌─────────────────────────────┬─────────────────────────────┐
101       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
102       ├─────────────────────────────┼─────────────────────────────┤
103       │Interface Stability          │Committed                    │
104       ├─────────────────────────────┼─────────────────────────────┤
105       │MT-Level                     │See below.                   │
106       ├─────────────────────────────┼─────────────────────────────┤
107       │Standard                     │See below.                   │
108       └─────────────────────────────┴─────────────────────────────┘
109
110
111       All  of  these  functions  can be used safely in multithreaded applica‐
112       tions, as long as setlocale(3C) is  not  being  called  to  change  the
113       locale.
114
115
116       See   standards(5)   for   the   standards  conformance  of  vprintf(),
117       vfprintf(), vsprintf(), and vsnprintf(). The  vasprintf()  function  is
118       modeled  on  the  one  that  appears  in the FreeBSD, NetBSD, and GNU C
119       libraries.
120

SEE ALSO

122       printf(3C), attributes(5), stdarg(3EXT), attributes(5), standards(5)
123

NOTES

125       The vsnprintf() return value when n = 0 was changed in the  Solaris  10
126       release.  The change was based on the SUSv3 specification. The previous
127       behavior  was  based  on  the  initial   SUSv2   specification,   where
128       vsnprintf() when n = 0 returns an unspecified value less than 1.
129
130
131
132SunOS 5.11                        7 Jan 2009                       vprintf(3C)
Impressum