Next: , Previous: stdio_ext, Up: Stdio


4.64 swprintf, fwprintf, wprintf—wide character format output

Synopsis

     #include <wchar.h>
     
     int wprintf(const wchar_t *format, ...);
     int fwprintf(FILE *__restrict fd,
         const wchar_t *__restrict format, ...);
     int swprintf(wchar_t *__restrict str, size_t size,
         const wchar_t *__restrict format, ...);
     
     int _wprintf_r(struct _reent *ptr, const wchar_t *format, ...);
     int _fwprintf_r(struct _reent *ptr, FILE *fd,
         const wchar_t *format, ...);
     int _swprintf_r(struct _reent *ptr, wchar_t *str,
         size_t size, const wchar_t *format, ...);
     

Description
wprintf accepts a series of arguments, applies to each a format specifier from *format, and writes the formatted data to stdout, without a terminating NUL wide character. The behavior of wprintf is undefined if there are not enough arguments for the format or if any argument is not the right type for the corresponding conversion specifier. wprintf returns when it reaches the end of the format string. If there are more arguments than the format requires, excess arguments are ignored.

fwprintf is like wprintf, except that output is directed to the stream fd rather than stdout.

swprintf is like wprintf, except that output is directed to the buffer str with a terminating wide NUL, and the resulting string length is limited to at most size wide characters, including the terminating NUL. It is considered an error if the output (including the terminating wide-NULL) does not fit into size wide characters. (This error behavior is not the same as for snprintf, which swprintf is otherwise completely analogous to. While snprintf allows the needed size to be known simply by giving size=0, swprintf does not, giving an error instead.)

For swprintf the behavior is undefined if the output *str overlaps with one of the arguments. Behavior is also undefined if the argument for %n within *format overlaps another argument.

format is a pointer to a wide character string containing two types of objects: ordinary characters (other than %), which are copied unchanged to the output, and conversion specifications, each of which is introduced by %. (To include % in the output, use %% in the format string.) A conversion specification has the following form:

            %[pos][flags][width][.prec][size]type

The fields of the conversion specification have the following meanings:

_wprintf_r, _fwprintf_r, _swprintf_r, are simply reentrant versions of the functions above.


Returns
On success, swprintf return the number of wide characters in the output string, except the concluding NUL is not counted. wprintf and fwprintf return the number of characters transmitted.

If an error occurs, the result of wprintf, fwprintf, and swprintf is a negative value. For wprintf and fwprintf, errno may be set according to fputwc. For swprintf, errno may be set to EOVERFLOW if size is greater than INT_MAX / sizeof (wchar_t), or when the output does not fit into size wide characters (including the terminating wide NULL).


Bugs
The “”' (quote) flag does not work when locale's thousands_sep is not empty.

Portability
POSIX-1.2008 with extensions; C99 (compliant except for POSIX extensions).

Depending on how newlib was configured, not all format specifiers are supported.

Supporting OS subroutines required: close, fstat, isatty, lseek, read, sbrk, write.