FWPRINTF(3POSIX)
π FWPRINTF(3POSIX) β POSIX Programmer's Manual π
okay bestie, welcome to FWPRINTF(3POSIX) from the POSIX Programmer's Manual β it's giving very legal, very wide-character, very formatted output energy. π«Ά
πΈ PROLOG πΈ
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. π
β¨ NAME β¨
fwprintf, swprintf, wprintf β print formatted wide-character output π
π¦ SYNOPSIS π¦
#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, ...);
π DESCRIPTION π
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. periodt. β¨
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). no cap. π
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. undefined behavior is not cute, bestie. π
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). iykyk. π
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. obsessed. π
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(). lowkey mysterious. π
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> ('.'). slay. π
Each conversion specification is introduced by the '%' wide character or by the wide-character sequence "%n$", after which the following appear in sequence:
- Zero or more flags (in any order), which modify the meaning of the conversion specification. π
- An optional minimum field width. If the converted value has fewer wide characters than the field width, it shall be padded with
<space>characters by default on the left; it shall be padded on the right, if the left-adjustment flag ('-'), described below, is given to the field width. The field width takes the form of an<asterisk>('*'), described below, or a decimal integer. β¨ - An optional precision that gives the minimum number of digits to appear for the
d,i,o,u,x, andXconversion specifiers; the number of digits to appear after the radix character for thea,A,e,E,f, andFconversion specifiers; the maximum number of significant digits for thegandGconversion specifiers; or the maximum number of wide characters to be printed from a string in thesconversion specifiers. The precision takes the form of a<period>('.') followed either by an<asterisk>('*'), described below, or an optional decimal digit string, where a null digit string is treated as0. If a precision appears with any other conversion wide character, the behavior is undefined. π¨ - An optional length modifier that specifies the size of the argument. π
- A conversion specifier wide character that indicates the type of conversion to be applied. π
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<apostrophe>.) The integer portion of the result of a decimal conversion (%i,%d,%u,%f,%F,%g, or%G) shall be formatted with thousands' grouping wide characters. For other conversions, the behavior is undefined. The numeric grouping wide character is used. π-β The result of the conversion shall be left-justified within the field. The conversion shall be right-justified if this flag is not specified. β¨+β The result of a signed conversion shall always begin with a sign ('+'or'-'). The conversion shall begin with a sign only when a negative value is converted if this flag is not specified. π<space>β If the first wide character of a signed conversion is not a sign, or if a signed conversion results in no wide characters, a<space>shall be prefixed to the result. This means that if the<space>and'+'flags both appear, the<space>flag shall be ignored. π«Ά#β Specifies that the value is to be converted to an alternative form. Foroconversion, it shall increase the precision, if and only if necessary, to force the first digit of the result to be zero (if the value and precision are both0, a single0is printed). ForxorXconversion specifiers, a non-zero result shall have0x(or0X) prefixed to it. Fora,A,e,E,f,F,g, andGconversion specifiers, the result shall always contain a radix character, even if no digits follow it. Without this flag, a radix character appears in the result of these conversions only if a digit follows it. ForgandGconversion specifiers, trailing zeros shall not be removed from the result as they normally are. For other conversion specifiers, the behavior is undefined. π₯0β Ford,i,o,u,x,X,a,A,e,E,f,F,g, andGconversion specifiers, leading zeros (following any indication of sign or base) are used to pad to the field width rather than performing space padding, except when converting an infinity or NaN. If the'0'and'-'flags both appear, the'0'flag shall be ignored. Ford,i,o,u,x, andXconversion specifiers, if a precision is specified, the'0'flag shall be ignored. If the'0'and<apostrophe>flags both appear, the grouping wide characters are inserted before zero padding. For other conversions, the behavior is undefined. π
The length modifiers and their meanings are:
hhβ Specifies that a followingd,i,o,u,x, orXconversion specifier applies to asigned charorunsigned charargument (the argument will have been promoted according to the integer promotions, but its value shall be converted tosigned charorunsigned charbefore printing); or that a followingnconversion specifier applies to a pointer to asigned charargument. πhβ Specifies that a followingd,i,o,u,x, orXconversion specifier applies to ashortorunsigned shortargument (the argument will have been promoted according to the integer promotions, but its value shall be converted toshortorunsigned shortbefore printing); or that a followingnconversion specifier applies to a pointer to ashortargument. β¨l(ell) β Specifies that a followingd,i,o,u,x, orXconversion specifier applies to alongorunsigned longargument; that a followingnconversion specifier applies to a pointer to alongargument; that a followingcconversion specifier applies to awint_targument; that a followingsconversion specifier applies to a pointer to awchar_targument; or has no effect on a followinga,A,e,E,f,F,g, orGconversion specifier. πll(ell-ell) β Specifies that a followingd,i,o,u,x, orXconversion specifier applies to along longorunsigned long longargument; or that a followingnconversion specifier applies to a pointer to along longargument. πjβ Specifies that a followingd,i,o,u,x, orXconversion specifier applies to anintmax_toruintmax_targument; or that a followingnconversion specifier applies to a pointer to anintmax_targument. πzβ okay so this one says the nextd,i,o,u,x, orXconversion specifier is working with asize_t, or the signed integer type that matches it. Or, plot twist, that a followingnconversion specifier is pointing at a signed integer type that corresponds to asize_targument. π«Άtβ same energy, different type: a followingd,i,o,u,x, orXapplies to aptrdiff_tor the matching unsigned type. And a followingnapplies to a pointer to aptrdiff_targument.Lβ this one is for the long-double girlies π . It says a followinga,A,e,E,f,F,g, orGconversion specifier applies to along doubleargument.
β οΈ And if a length modifier shows up with any conversion specifier that isn't one of the ones listed above? The behavior is undefined. Not "undefined-ish", not "we'll figure it out" β undefined, bestie. Don't do it. π
β¨ the conversion specifiers and their meanings β¨
d,iβ theintargument gets converted to a signed decimal, styled like[-]dddd. The precision is the minimum number of digits that show up; if your value fits in fewer digits, it gets padded out with leading zeros. Default precision is1. And converting zero with an explicit precision of zero gives you no wide characters. Zero characters. Nothing. β¨oβ the unsigned argument gets converted to unsigned octal, styled likedddd. Precision = minimum digits, pad with leading zeros if it's short. Default precision is1. Converting zero with an explicit precision of zero β no wide characters.uβ the unsigned argument gets converted to unsigned decimal, styled likedddd. Precision = minimum digits, leading zeros do the filling in. Default precision is1. Zero with an explicit precision of zero β no wide characters.xβ the unsigned argument gets converted to unsigned hexadecimal, styled likedddd, and lowercaseabcdefare the letters in play. Precision = minimum digits, padded with leading zeros. Default precision is1. Zero with an explicit precision of zero β no wide characters.Xβ literally the same asx, except it'sABCDEFinstead ofabcdef. Uppercase slay. πf,Fβ thedoubleargument gets converted to decimal notation, styled like[-]ddd.ddd, and the number of digits after the radix character equals the precision you specified. Precision missing? It's taken as6. Precision explicitly zero and no'#'flag present? Then no radix character appears at all. If a radix character does appear, at least one digit shows up before it. The value gets rounded to the right number of digits in an implementation-defined manner.
A double argument representing an infinity gets converted in one of the styles [-]inf or [-]infinity β which one is implementation-defined. A double representing a NaN gets converted in one of the styles [-]nan or [-]nan(n-char-sequence) β again, which style, and what any n-char-sequence even means, is implementation-defined. And the F conversion specifier produces INF, INFINITY, or NAN instead of inf, infinity, or nan, respectively. Uppercase feelings. π
e,Eβ thedoubleargument gets converted in the style[-]d.dddeΒ±dd, with exactly one digit before the radix character (and that digit is non-zero if the argument is non-zero), and the digits after it equal to the precision. Precision missing? Taken as6. Precision zero and no'#'flag present? No radix character. The value gets rounded to the appropriate number of digits in an implementation-defined manner. TheEconversion wide character produces a number withEinstead ofeintroducing the exponent. The exponent always contains at least two digits, and if the value is zero, the exponent is zero.
A double argument representing an infinity or NaN gets converted in the style of an f or F conversion specifier.
g,Gβ adoubleargument representing a floating-point number gets converted in stylefore(or styleForEwhen it's aGconversion specifier), and which one depends on the value being converted and the precision. So let P equal the precision if it's non-zero,6if the precision was omitted, or1if the precision is zero. Then, if a conversion with styleEwould have an exponent of X:- If
P>Xβ₯-4, the conversion is with stylef(orF) and precisionP-(X+1). - Otherwise, the conversion is with style
e(orE) and precisionP-1.
- If
And finally, unless the '#' flag is used, any trailing zeros get removed from the fractional portion of the result, and the decimal-point character gets removed too if there's no fractional portion left over. Cleaned up. β¨
A double argument representing an infinity or NaN gets converted in the style of an f or F conversion specifier.
a,Aβ adoubleargument representing a floating-point number gets converted in the style[-]0xh.hhhhpΒ±d, where there's one hexadecimal digit before the decimal-point wide character (non-zero if the argument is a normalized floating-point number, otherwise unspecified), and the number of hexadecimal digits after it equals the precision. If the precision is missing andFLT_RADIXis a power of 2, then the precision is enough for an exact representation of the value. If the precision is missing andFLT_RADIXis not a power of 2, then the precision is enough to distinguish values of typedouble, except trailing zeros may be omitted. If the precision is zero and the'#'flag isn't specified, no decimal-point wide character appears. The lettersabcdefare used for anaconversion andABCDEFfor anAconversion. TheAconversion specifier produces a number withXandPinstead ofxandp. The exponent always contains at least one digit β and only as many more digits as necessary to represent the decimal exponent of 2. If the value is zero, the exponent is zero.
A double argument representing an infinity or NaN gets converted in the style of an f or F conversion specifier.
cβ if there's nol(ell) qualifier hanging around, theintargument gets converted to a wide character as if by calling thebtowc()function, and that resulting wide character gets written. Otherwise, thewint_targument gets converted towchar_t, and written. π¦sβ if there's nol(ell) qualifier, the application shall ensure the argument is a pointer to a character array holding a character sequence that begins in the initial shift state. Characters from that array get converted as if by repeated calls to thembrtowc()function β with the conversion state described by anmbstate_tobject initialized to zero before the first character is converted β and written up to (but not including) the terminating null wide character. If the precision is specified, no more than that many wide characters get written. If the precision isn't specified, or is greater than the size of the array, the application shall ensure the array contains a null wide character.
If an l (ell) qualifier is present, the application shall ensure the argument is a pointer to an array of type wchar_t. Wide characters from that array get written up to (but not including) a terminating null wide character. If no precision is specified, or it's greater than the size of the array, the application shall ensure the array contains a null wide character. If a precision is specified, no more than that many wide characters get written.
pβ the application shall ensure the argument is a pointer tovoid. The value of that pointer gets converted to a sequence of printable wide characters, in an implementation-defined manner. iykyk πnβ the application shall ensure the argument is a pointer to an integer, and into that integer gets written the number of wide characters written to the output so far by this call to one of thefwprintf()functions. No argument gets converted, but one shall be consumed. And if the conversion specification includes any flags, a field width, or a precision, the behavior is undefined. πCβ equivalent tolc.Sβ equivalent tols.%β outputs a'%'wide character; no argument gets converted. The entire conversion specification shall be%%. That's it, that's the whole vibe.
β οΈ If a conversion specification doesn't match one of the forms above, the behavior is undefined. Periodt.
Okay and one more thing that's lowkey important: 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 just gets expanded to contain the conversion result. The field does not clip your content, bestie, it makes room. π
Also, characters generated by fwprintf() and wprintf() shall be printed as if fputwc() had been called.
And for a and A conversions: if FLT_RADIX is not a power of 2 and the result isn't 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. Fancy math behavior, honestly iconic. β
okay so for the 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(). fr fr.
RETURN VALUE π
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.
ERRORS π
For the conditions under which fwprintf() and wprintf() fail and may fail, refer to fputwc().
In addition, all forms of fwprintf() shall fail if:
EILSEQβ A wide-character code that does not correspond to a valid character has been detected.
In addition, fwprintf() and wprintf() may fail if:
ENOMEMβ Insufficient storage space is available.
The swprintf() shall fail if:
EOVERFLOWβ The value ofnis greater than{INT_MAX}or the number of bytes needed to hold the output excluding the terminating null is greater than{INT_MAX}.
The following sections are informative.
EXAMPLES β¨
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
APPLICATION USAGE π¦
None. Like, truly none. That's the vibe.
RATIONALE π
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.
FUTURE DIRECTIONS π
None. We're good, bestie.
SEE ALSO π
- 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>
COPYRIGHT π
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 athttp://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, seehttps://www.kernel.org/doc/man-pages/reporting_bugs.html.
And that's a wrap! Source/version: IEEE/The Open Group, 2017 β page: FWPRINTF(3POSIX). Stay iconic, bestie! π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms