FWPRINTF(3POSIX) | POSIX Programmer's Manual | FWPRINTF(3POSIX) |
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
fwprintf, swprintf, wprintf — print formatted wide-character output
#include <stdio.h> #include <wchar.h>
int fwprintf(FILE *restrict stream, const wchar_t *restrict format, ...); int swprintf(wchar_t *restrict ws, size_t n, const wchar_t *restrict format, ...); int wprintf(const wchar_t *restrict format, ...);
The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional. This volume of POSIX.1‐2017 defers to the ISO C standard.
The fwprintf() function shall place output on the named output stream. The wprintf() function shall place output on the standard output stream stdout. The swprintf() function shall place output followed by the null wide character in consecutive wide characters starting at *ws; no more than n wide characters shall be written, including a terminating null wide character, which is always added (unless n is zero).
Each of these functions shall convert, format, and print its arguments under control of the format wide-character string. The format is composed of zero or more directives: ordinary wide-characters, which are simply copied to the output stream, and conversion specifications, each of which results in the fetching of zero or more arguments. The results are undefined if there are insufficient arguments for the format. If the format is exhausted while arguments remain, the excess arguments are evaluated but are otherwise ignored.
Conversions can be applied to the nth argument after the format in the argument list, rather than to the next unused argument. In this case, the conversion specifier wide character % (see below) is replaced by the sequence "%n$", where n is a decimal integer in the range [1,{NL_ARGMAX}], giving the position of the argument in the argument list. This feature provides for the definition of format wide-character strings that select arguments in an order appropriate to specific languages (see the EXAMPLES section).
The format can contain either numbered argument specifications (that is, "%n$" and "*m$"), or unnumbered argument conversion specifications (that is, % and *), but not both. The only exception to this is that %% can be mixed with the "%n$" form. The results of mixing numbered and unnumbered argument specifications in a format wide-character string are undefined. When numbered argument specifications are used, specifying the Nth argument requires that all the leading arguments, from the first to the (N-1)th, are specified in the format wide-character string.
In format wide-character strings containing the "%n$" form of conversion specification, numbered arguments in the argument list can be referenced from the format wide-character string as many times as required.
In format wide-character strings containing the % form of conversion specification, each argument in the argument list shall be used exactly once. It is unspecified whether an encoding error occurs if the format string contains wchar_t values that do not correspond to members of the character set of the current locale and the specified semantics do not require that value to be processed by wcrtomb().
All forms of the fwprintf() function allow for the
insertion of a locale-dependent radix character in the output string, output
as a wide-character value. The radix character is defined in the current
locale (category LC_NUMERIC). In the POSIX locale, or in a locale
where the radix character is not defined, the radix character shall default
to a <period> ('.').
Each conversion specification is introduced by the '%' wide character or by the wide-character sequence "%n$", after which the following appear in sequence:
A field width, or precision, or both, may be indicated by an <asterisk> ('*'). In this case an argument of type int supplies the field width or precision. Applications shall ensure that arguments specifying field width, or precision, or both appear in that order before the argument, if any, to be converted. A negative field width is taken as a '-' flag followed by a positive field width. A negative precision is taken as if the precision were omitted. In format wide-character strings containing the "%n$" form of a conversion specification, a field width or precision may be indicated by the sequence "*m$", where m is a decimal integer in the range [1,{NL_ARGMAX}] giving the position in the argument list (after the format argument) of an integer argument containing the field width or precision, for example:
wprintf(L"%1$d:%2$.*3$d:%4$.*3$d\n", hour, min, precision, sec);
The flag wide characters and their meanings are:
The length modifiers and their meanings are:
If a length modifier appears with any conversion specifier other than as specified above, the behavior is undefined.
The conversion specifiers and their meanings are:
A double argument representing an infinity shall be converted in one of the styles "[-]inf" or "[-]infinity"; which style is implementation-defined. A double argument representing a NaN shall be converted in one of the styles "[-]nan" or "[-]nan(n-char-sequence)"; which style, and the meaning of any n-char-sequence, is implementation-defined. The F conversion specifier produces "INF", "INFINITY", or "NAN" instead of "inf", "infinity", or "nan", respectively.
A double argument representing an infinity or NaN shall be converted in the style of an f or F conversion specifier.
Finally, unless the '#' flag is used, any trailing zeros shall be removed from the fractional portion of the result and the decimal-point character shall be removed if there is no fractional portion remaining.
A double argument representing an infinity or NaN shall be converted in the style of an f or F conversion specifier.
A double argument representing an infinity or NaN shall be converted in the style of an f or F conversion specifier.
If an l (ell) qualifier is present, the application shall ensure that the argument is a pointer to an array of type wchar_t. Wide characters from the array shall be written up to (but not including) a terminating null wide character. If no precision is specified, or is greater than the size of the array, the application shall ensure that the array contains a null wide character. If a precision is specified, no more than that many wide characters shall be written.
If a conversion specification does not match one of the above forms, the behavior is undefined.
In no case does a nonexistent or small field width cause truncation of a field; if the result of a conversion is wider than the field width, the field shall be expanded to contain the conversion result. Characters generated by fwprintf() and wprintf() shall be printed as if fputwc() had been called.
For a and A conversions, if FLT_RADIX is not a power of 2 and the result is not exactly representable in the given precision, the result should be one of the two adjacent numbers in hexadecimal floating style with the given precision, with the extra stipulation that the error should have a correct sign for the current rounding direction.
For e, E, f, F, g, and G conversion specifiers, if the number of significant decimal digits is at most DECIMAL_DIG, then the result should be correctly rounded. If the number of significant decimal digits is more than DECIMAL_DIG but the source value is exactly representable with DECIMAL_DIG digits, then the result should be an exact representation with trailing zeros. Otherwise, the source value is bounded by two adjacent decimal strings L < U, both having DECIMAL_DIG significant digits; the value of the resultant decimal string D should satisfy L <= D <= U, with the extra stipulation that the error should have a correct sign for the current rounding direction.
The last data modification and last file status change timestamps of the file shall be marked for update between the call to a successful execution of fwprintf() or wprintf() and the next successful completion of a call to fflush() or fclose() on the same stream, or a call to exit() or abort().
Upon successful completion, these functions shall return the number of wide characters transmitted, excluding the terminating null wide character in the case of swprintf(), or a negative value if an output error was encountered, and set errno to indicate the error.
If n or more wide characters were requested to be written, swprintf() shall return a negative value, and set errno to indicate the error.
For the conditions under which fwprintf() and wprintf() fail and may fail, refer to fputwc().
In addition, all forms of fwprintf() shall fail if:
In addition, fwprintf() and wprintf() may fail if:
The swprintf() shall fail if:
The following sections are informative.
To print the language-independent date and time format, the following statement could be used:
wprintf(format, weekday, month, day, hour, min);
For American usage, format could be a pointer to the wide-character string:
L"%s, %s %d, %d:%.2d\n"
producing the message:
Sunday, July 3, 10:02
whereas for German usage, format could be a pointer to the wide-character string:
L"%1$s, %3$d. %2$s, %4$d:%5$.2d\n"
producing the message:
Sonntag, 3. Juli, 10:02
None.
If an implementation detects that there are insufficient arguments for the format, it is recommended that the function should fail and report an [EINVAL] error.
None.
Section 2.5, Standard I/O Streams, btowc(), fputwc(), fwscanf(), mbrtowc(), setlocale()
The Base Definitions volume of POSIX.1‐2017, Chapter 7, Locale, <inttypes.h>, <stdio.h>, <wchar.h>
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version 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 .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
2017 | IEEE/The Open Group |