Blame man-pages-posix-2013-a/man3p/fprintf.3p

Packit 7cfc04
'\" et
Packit 7cfc04
.TH FPRINTF "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
Packit 7cfc04
.SH PROLOG
Packit 7cfc04
This manual page is part of the POSIX Programmer's Manual.
Packit 7cfc04
The Linux implementation of this interface may differ (consult
Packit 7cfc04
the corresponding Linux manual page for details of Linux behavior),
Packit 7cfc04
or the interface may not be implemented on Linux.
Packit 7cfc04
Packit 7cfc04
.SH NAME
Packit 7cfc04
dprintf,
Packit 7cfc04
fprintf,
Packit 7cfc04
printf,
Packit 7cfc04
snprintf,
Packit 7cfc04
sprintf
Packit 7cfc04
\(em print formatted output
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.LP
Packit 7cfc04
.nf
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
.P
Packit 7cfc04
int dprintf(int \fIfildes\fP, const char *restrict \fIformat\fP, ...);
Packit 7cfc04
int fprintf(FILE *restrict \fIstream\fP, const char *restrict \fIformat\fP, ...);
Packit 7cfc04
int printf(const char *restrict \fIformat\fP, ...);
Packit 7cfc04
int snprintf(char *restrict \fIs\fP, size_t \fIn\fP,
Packit 7cfc04
    const char *restrict \fIformat\fP, ...);
Packit 7cfc04
int sprintf(char *restrict \fIs\fP, const char *restrict \fIformat\fP, ...);
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
Excluding
Packit 7cfc04
\fIdprintf\fR():
Packit 7cfc04
The functionality described on this reference page is aligned with the
Packit 7cfc04
ISO\ C standard. Any conflict between the requirements described here and the
Packit 7cfc04
ISO\ C standard is unintentional. This volume of POSIX.1\(hy2008 defers to the ISO\ C standard.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
\fIfprintf\fR()
Packit 7cfc04
function shall place output on the named output
Packit 7cfc04
.IR stream .
Packit 7cfc04
The
Packit 7cfc04
\fIprintf\fR()
Packit 7cfc04
function shall place output on the standard output stream
Packit 7cfc04
.IR stdout .
Packit 7cfc04
The
Packit 7cfc04
\fIsprintf\fR()
Packit 7cfc04
function shall place output followed by the null byte,
Packit 7cfc04
.BR '\e0' ,
Packit 7cfc04
in consecutive bytes starting at *\fIs\fP; it is the user's
Packit 7cfc04
responsibility to ensure that enough space is available.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
\fIdprintf\fR()
Packit 7cfc04
function shall be equivalent to the
Packit 7cfc04
\fIfprintf\fR()
Packit 7cfc04
function, except that
Packit 7cfc04
\fIdprintf\fR()
Packit 7cfc04
shall write output to the file associated with the file descriptor
Packit 7cfc04
specified by the
Packit 7cfc04
.IR fildes
Packit 7cfc04
argument rather than place output on a stream.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
\fIsnprintf\fR()
Packit 7cfc04
function shall be equivalent to
Packit 7cfc04
\fIsprintf\fR(),
Packit 7cfc04
with the addition of the
Packit 7cfc04
.IR n
Packit 7cfc04
argument which states the size of the buffer referred to by
Packit 7cfc04
.IR s .
Packit 7cfc04
If
Packit 7cfc04
.IR n
Packit 7cfc04
is zero, nothing shall be written and
Packit 7cfc04
.IR s
Packit 7cfc04
may be a null pointer. Otherwise, output bytes beyond the
Packit 7cfc04
.IR n \(hy1st
Packit 7cfc04
shall be discarded instead of being written to the array, and a null
Packit 7cfc04
byte is written at the end of the bytes actually written into the
Packit 7cfc04
array.
Packit 7cfc04
.P
Packit 7cfc04
If copying takes place between objects that overlap as a result of a
Packit 7cfc04
call to
Packit 7cfc04
\fIsprintf\fR()
Packit 7cfc04
or
Packit 7cfc04
\fIsnprintf\fR(),
Packit 7cfc04
the results are undefined.
Packit 7cfc04
.P
Packit 7cfc04
Each of these functions converts, formats, and prints its arguments
Packit 7cfc04
under control of the
Packit 7cfc04
.IR format .
Packit 7cfc04
The
Packit 7cfc04
.IR format
Packit 7cfc04
is a character string, beginning and ending in its initial shift state,
Packit 7cfc04
if any. The
Packit 7cfc04
.IR format
Packit 7cfc04
is composed of zero or more directives:
Packit 7cfc04
.IR "ordinary characters" ,
Packit 7cfc04
which are simply copied to the output stream, and
Packit 7cfc04
.IR "conversion specifications" ,
Packit 7cfc04
each of which shall result in the fetching of zero or more arguments.
Packit 7cfc04
The results are undefined if there are insufficient arguments for the
Packit 7cfc04
.IR format .
Packit 7cfc04
If the
Packit 7cfc04
.IR format
Packit 7cfc04
is exhausted while arguments remain, the excess arguments shall be
Packit 7cfc04
evaluated but are otherwise ignored.
Packit 7cfc04
.P
Packit 7cfc04
Conversions can be applied to the
Packit 7cfc04
.IR n th
Packit 7cfc04
argument after the
Packit 7cfc04
.IR format
Packit 7cfc04
in the argument list, rather than to the next unused argument. In this
Packit 7cfc04
case, the conversion specifier character
Packit 7cfc04
.BR %
Packit 7cfc04
(see below) is replaced by the sequence \fR"%\fIn\fR$"\fR, where
Packit 7cfc04
.IR n
Packit 7cfc04
is a decimal integer in the range [1,{NL_ARGMAX}],
Packit 7cfc04
giving the position of the argument in the argument list. This feature
Packit 7cfc04
provides for the definition of format strings that select arguments in
Packit 7cfc04
an order appropriate to specific languages (see the EXAMPLES section).
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR format
Packit 7cfc04
can contain either numbered argument conversion specifications (that
Packit 7cfc04
is, \fR"%\fIn\fR$"\fR and \fR"*\fIm\fR$"\fR), or unnumbered argument
Packit 7cfc04
conversion specifications (that is,
Packit 7cfc04
.BR %
Packit 7cfc04
and
Packit 7cfc04
.BR * ),
Packit 7cfc04
but not both. The only exception to this is that
Packit 7cfc04
.BR %%
Packit 7cfc04
can be mixed with the \fR"%\fIn\fR$"\fR form. The results of mixing
Packit 7cfc04
numbered and unnumbered argument specifications in a
Packit 7cfc04
.IR format
Packit 7cfc04
string are undefined. When numbered argument specifications are used,
Packit 7cfc04
specifying the
Packit 7cfc04
.IR N th
Packit 7cfc04
argument requires that all the leading arguments, from the first to the
Packit 7cfc04
(\fIN\(mi1\fP)th, are specified in the format string.
Packit 7cfc04
.P
Packit 7cfc04
In format strings containing the \fR"%\fIn\fR$"\fR form of conversion
Packit 7cfc04
specification, numbered arguments in the argument list can be
Packit 7cfc04
referenced from the format string as many times as required.
Packit 7cfc04
.P
Packit 7cfc04
In format strings containing the
Packit 7cfc04
.BR %
Packit 7cfc04
form of conversion specification, each conversion specification uses
Packit 7cfc04
the first unused argument in the argument list.
Packit 7cfc04
.P
Packit 7cfc04
All forms of the
Packit 7cfc04
\fIfprintf\fR()
Packit 7cfc04
functions allow for the insertion of a language-dependent radix
Packit 7cfc04
character in the output string. The radix character is defined in the
Packit 7cfc04
current locale (category
Packit 7cfc04
.IR LC_NUMERIC ).
Packit 7cfc04
In the POSIX locale, or in a locale where the radix character is not
Packit 7cfc04
defined, the radix character shall default to a
Packit 7cfc04
<period>
Packit 7cfc04
(\c
Packit 7cfc04
.BR '.' ).
Packit 7cfc04
.P
Packit 7cfc04
Each conversion specification is introduced by the
Packit 7cfc04
.BR '%' 
Packit 7cfc04
character
Packit 7cfc04
or by the character sequence \fR"%\fIn\fR$"\fR,
Packit 7cfc04
after which the following appear in sequence:
Packit 7cfc04
.IP " *" 4
Packit 7cfc04
Zero or more
Packit 7cfc04
.IR flags
Packit 7cfc04
(in any order), which modify the meaning of the conversion
Packit 7cfc04
specification.
Packit 7cfc04
.IP " *" 4
Packit 7cfc04
An optional minimum
Packit 7cfc04
.IR "field width" .
Packit 7cfc04
If the converted value has fewer bytes than the field width, it shall
Packit 7cfc04
be padded with
Packit 7cfc04
<space>
Packit 7cfc04
characters by default on the left; it shall be padded on the right if
Packit 7cfc04
the left-adjustment flag (\c
Packit 7cfc04
.BR '\(mi' ),
Packit 7cfc04
described below, is given to the field width. The field width takes the
Packit 7cfc04
form of an
Packit 7cfc04
<asterisk>
Packit 7cfc04
(\c
Packit 7cfc04
.BR '*' ),
Packit 7cfc04
described below, or a decimal integer.
Packit 7cfc04
.IP " *" 4
Packit 7cfc04
An optional
Packit 7cfc04
.IR precision
Packit 7cfc04
that gives the minimum number of digits to appear for the
Packit 7cfc04
.BR d ,
Packit 7cfc04
.BR i ,
Packit 7cfc04
.BR o ,
Packit 7cfc04
.BR u ,
Packit 7cfc04
.BR x ,
Packit 7cfc04
and
Packit 7cfc04
.BR X
Packit 7cfc04
conversion specifiers; the number of digits to appear after the radix
Packit 7cfc04
character for the
Packit 7cfc04
.BR a ,
Packit 7cfc04
.BR A ,
Packit 7cfc04
.BR e ,
Packit 7cfc04
.BR E ,
Packit 7cfc04
.BR f ,
Packit 7cfc04
and
Packit 7cfc04
.BR F
Packit 7cfc04
conversion specifiers; the maximum number of significant digits for the
Packit 7cfc04
.BR g
Packit 7cfc04
and
Packit 7cfc04
.BR G
Packit 7cfc04
conversion specifiers; or the maximum number of bytes to be printed
Packit 7cfc04
from a string in the
Packit 7cfc04
.BR s
Packit 7cfc04
and
Packit 7cfc04
.BR S
Packit 7cfc04
conversion specifiers. The precision takes the form of a
Packit 7cfc04
<period>
Packit 7cfc04
(\c
Packit 7cfc04
.BR '.' )
Packit 7cfc04
followed either by an
Packit 7cfc04
<asterisk>
Packit 7cfc04
(\c
Packit 7cfc04
.BR '*' ),
Packit 7cfc04
described below, or an optional decimal digit string, where a null
Packit 7cfc04
digit string is treated as zero. If a precision appears with any other
Packit 7cfc04
conversion specifier, the behavior is undefined.
Packit 7cfc04
.IP " *" 4
Packit 7cfc04
An optional length modifier that specifies the size of the argument.
Packit 7cfc04
.IP " *" 4
Packit 7cfc04
A
Packit 7cfc04
.IR "conversion specifier"
Packit 7cfc04
character that indicates the type of conversion to be applied.
Packit 7cfc04
.P
Packit 7cfc04
A field width, or precision, or both, may be indicated by an
Packit 7cfc04
<asterisk>
Packit 7cfc04
(\c
Packit 7cfc04
.BR '*' ).
Packit 7cfc04
In this case an argument of type
Packit 7cfc04
.BR int
Packit 7cfc04
supplies the field width or precision. Applications shall ensure that
Packit 7cfc04
arguments specifying field width, or precision, or both appear in that
Packit 7cfc04
order before the argument, if any, to be converted. A negative field
Packit 7cfc04
width is taken as a
Packit 7cfc04
.BR '\(mi' 
Packit 7cfc04
flag followed by a positive field width. A negative precision is taken
Packit 7cfc04
as if the precision were omitted.
Packit 7cfc04
In
Packit 7cfc04
.IR format
Packit 7cfc04
strings containing the \fR"%\fIn\fR$"\fR form of a
Packit 7cfc04
conversion specification, a field width or precision may be indicated
Packit 7cfc04
by the sequence \fR"*\fIm\fR$"\fR, where
Packit 7cfc04
.IR m
Packit 7cfc04
is a decimal integer in the range [1,{NL_ARGMAX}] giving the position
Packit 7cfc04
in the argument list (after the
Packit 7cfc04
.IR format
Packit 7cfc04
argument) of an integer argument containing the field width or
Packit 7cfc04
precision, for example:
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
printf("%1$d:%2$.*3$d:%4$.*3$d\en", hour, min, precision, sec);
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.P
Packit 7cfc04
The flag characters and their meanings are:
Packit 7cfc04
.IP "\fR'\fR" 8
Packit 7cfc04
(The
Packit 7cfc04
<apostrophe>.)
Packit 7cfc04
The integer portion of the result of a decimal conversion (\c
Packit 7cfc04
.BR %i ,
Packit 7cfc04
.BR %d ,
Packit 7cfc04
.BR %u ,
Packit 7cfc04
.BR %f ,
Packit 7cfc04
.BR %F ,
Packit 7cfc04
.BR %g ,
Packit 7cfc04
or
Packit 7cfc04
.BR %G )
Packit 7cfc04
shall be formatted with thousands' grouping characters. For other
Packit 7cfc04
conversions the behavior is undefined. The non-monetary grouping
Packit 7cfc04
character is used.
Packit 7cfc04
.IP "\fR\(mi\fR" 8
Packit 7cfc04
The result of the conversion shall be left-justified within the field.
Packit 7cfc04
The conversion is right-justified if this flag is not specified.
Packit 7cfc04
.IP "\fR+\fR" 8
Packit 7cfc04
The result of a signed conversion shall always begin with a sign (\c
Packit 7cfc04
.BR '+' 
Packit 7cfc04
or
Packit 7cfc04
.BR '\(mi' ).
Packit 7cfc04
The conversion shall begin with a sign only when a negative value is
Packit 7cfc04
converted if this flag is not specified.
Packit 7cfc04
.IP <space> 8
Packit 7cfc04
If the first character of a signed conversion is not a sign or if a
Packit 7cfc04
signed conversion results in no characters, a
Packit 7cfc04
<space>
Packit 7cfc04
shall be prefixed to the result. This means that if the
Packit 7cfc04
<space>
Packit 7cfc04
and
Packit 7cfc04
.BR '+' 
Packit 7cfc04
flags both appear, the
Packit 7cfc04
<space>
Packit 7cfc04
flag shall be ignored.
Packit 7cfc04
.IP "\fR#\fR" 8
Packit 7cfc04
Specifies that the value is to be converted to an alternative
Packit 7cfc04
form. For
Packit 7cfc04
.BR o
Packit 7cfc04
conversion, it increases the precision (if necessary) to force the
Packit 7cfc04
first digit of the result to be zero. For
Packit 7cfc04
.BR x
Packit 7cfc04
or
Packit 7cfc04
.BR X
Packit 7cfc04
conversion specifiers, a non-zero result shall have 0x (or 0X) prefixed
Packit 7cfc04
to it. For
Packit 7cfc04
.BR a ,
Packit 7cfc04
.BR A ,
Packit 7cfc04
.BR e ,
Packit 7cfc04
.BR E ,
Packit 7cfc04
.BR f ,
Packit 7cfc04
.BR F ,
Packit 7cfc04
.BR g ,
Packit 7cfc04
and
Packit 7cfc04
.BR G
Packit 7cfc04
conversion specifiers, the result shall always contain a radix
Packit 7cfc04
character, even if no digits follow the radix character. Without this
Packit 7cfc04
flag, a radix character appears in the result of these conversions only
Packit 7cfc04
if a digit follows it. For
Packit 7cfc04
.BR g
Packit 7cfc04
and
Packit 7cfc04
.BR G
Packit 7cfc04
conversion specifiers, trailing zeros shall
Packit 7cfc04
.IR not
Packit 7cfc04
be removed from the result as they normally are. For other conversion
Packit 7cfc04
specifiers, the behavior is undefined.
Packit 7cfc04
.IP "\fR0\fR" 8
Packit 7cfc04
For
Packit 7cfc04
.BR d ,
Packit 7cfc04
.BR i ,
Packit 7cfc04
.BR o ,
Packit 7cfc04
.BR u ,
Packit 7cfc04
.BR x ,
Packit 7cfc04
.BR X ,
Packit 7cfc04
.BR a ,
Packit 7cfc04
.BR A ,
Packit 7cfc04
.BR e ,
Packit 7cfc04
.BR E ,
Packit 7cfc04
.BR f ,
Packit 7cfc04
.BR F ,
Packit 7cfc04
.BR g ,
Packit 7cfc04
and
Packit 7cfc04
.BR G
Packit 7cfc04
conversion specifiers, leading zeros (following any indication of sign
Packit 7cfc04
or base) are used to pad to the field width rather than performing
Packit 7cfc04
space padding, except when converting an infinity or NaN. If the
Packit 7cfc04
.BR '0' 
Packit 7cfc04
and
Packit 7cfc04
.BR '\(mi' 
Packit 7cfc04
flags both appear, the
Packit 7cfc04
.BR '0' 
Packit 7cfc04
flag is ignored. For
Packit 7cfc04
.BR d ,
Packit 7cfc04
.BR i ,
Packit 7cfc04
.BR o ,
Packit 7cfc04
.BR u ,
Packit 7cfc04
.BR x ,
Packit 7cfc04
and
Packit 7cfc04
.BR X
Packit 7cfc04
conversion specifiers, if a precision is specified, the
Packit 7cfc04
.BR '0' 
Packit 7cfc04
flag shall be ignored.
Packit 7cfc04
If the
Packit 7cfc04
.BR '0' 
Packit 7cfc04
and
Packit 7cfc04
<apostrophe>
Packit 7cfc04
flags both appear, the grouping characters are inserted before zero
Packit 7cfc04
padding. For other conversions, the behavior is undefined.
Packit 7cfc04
.P
Packit 7cfc04
The length modifiers and their meanings are:
Packit 7cfc04
.IP "\fRhh\fR" 8
Packit 7cfc04
Specifies that a following
Packit 7cfc04
.BR d ,
Packit 7cfc04
.BR i ,
Packit 7cfc04
.BR o ,
Packit 7cfc04
.BR u ,
Packit 7cfc04
.BR x ,
Packit 7cfc04
or
Packit 7cfc04
.BR X
Packit 7cfc04
conversion specifier applies to a
Packit 7cfc04
.BR "signed char"
Packit 7cfc04
or
Packit 7cfc04
.BR "unsigned char"
Packit 7cfc04
argument (the argument will have been promoted according to the integer
Packit 7cfc04
promotions, but its value shall be converted to
Packit 7cfc04
.BR "signed char"
Packit 7cfc04
or
Packit 7cfc04
.BR "unsigned char"
Packit 7cfc04
before printing); or that a following
Packit 7cfc04
.BR n
Packit 7cfc04
conversion specifier applies to a pointer to a
Packit 7cfc04
.BR "signed char"
Packit 7cfc04
argument.
Packit 7cfc04
.IP "\fRh\fR" 8
Packit 7cfc04
Specifies that a following
Packit 7cfc04
.BR d ,
Packit 7cfc04
.BR i ,
Packit 7cfc04
.BR o ,
Packit 7cfc04
.BR u ,
Packit 7cfc04
.BR x ,
Packit 7cfc04
or
Packit 7cfc04
.BR X
Packit 7cfc04
conversion specifier applies to a
Packit 7cfc04
.BR "short"
Packit 7cfc04
or
Packit 7cfc04
.BR "unsigned short"
Packit 7cfc04
argument (the argument will have been promoted according to the integer
Packit 7cfc04
promotions, but its value shall be converted to
Packit 7cfc04
.BR "short"
Packit 7cfc04
or
Packit 7cfc04
.BR "unsigned short"
Packit 7cfc04
before printing); or that a following
Packit 7cfc04
.BR n
Packit 7cfc04
conversion specifier applies to a pointer to a
Packit 7cfc04
.BR "short"
Packit 7cfc04
argument.
Packit 7cfc04
.IP "\fRl\fR\ (ell)" 8
Packit 7cfc04
Specifies that a following
Packit 7cfc04
.BR d ,
Packit 7cfc04
.BR i ,
Packit 7cfc04
.BR o ,
Packit 7cfc04
.BR u ,
Packit 7cfc04
.BR x ,
Packit 7cfc04
or
Packit 7cfc04
.BR X
Packit 7cfc04
conversion specifier applies to a
Packit 7cfc04
.BR "long"
Packit 7cfc04
or
Packit 7cfc04
.BR "unsigned long"
Packit 7cfc04
argument; that a following
Packit 7cfc04
.BR n
Packit 7cfc04
conversion specifier applies to a pointer to a
Packit 7cfc04
.BR "long"
Packit 7cfc04
argument; that a following
Packit 7cfc04
.BR c
Packit 7cfc04
conversion specifier applies to a
Packit 7cfc04
.BR wint_t
Packit 7cfc04
argument; that a following
Packit 7cfc04
.BR s
Packit 7cfc04
conversion specifier applies to a pointer to a
Packit 7cfc04
.BR wchar_t
Packit 7cfc04
argument; or has no effect on a following
Packit 7cfc04
.BR a ,
Packit 7cfc04
.BR A ,
Packit 7cfc04
.BR e ,
Packit 7cfc04
.BR E ,
Packit 7cfc04
.BR f ,
Packit 7cfc04
.BR F ,
Packit 7cfc04
.BR g ,
Packit 7cfc04
or
Packit 7cfc04
.BR G
Packit 7cfc04
conversion specifier.
Packit 7cfc04
.IP "\fRll\fR\ (ell-ell)" 8
Packit 7cfc04
.br
Packit 7cfc04
Specifies that a following
Packit 7cfc04
.BR d ,
Packit 7cfc04
.BR i ,
Packit 7cfc04
.BR o ,
Packit 7cfc04
.BR u ,
Packit 7cfc04
.BR x ,
Packit 7cfc04
or
Packit 7cfc04
.BR X
Packit 7cfc04
conversion specifier applies to a
Packit 7cfc04
.BR "long long"
Packit 7cfc04
or
Packit 7cfc04
.BR "unsigned long long"
Packit 7cfc04
argument; or that a following
Packit 7cfc04
.BR n
Packit 7cfc04
conversion specifier applies to a pointer to a
Packit 7cfc04
.BR "long long"
Packit 7cfc04
argument.
Packit 7cfc04
.IP "\fRj\fR" 8
Packit 7cfc04
Specifies that a following
Packit 7cfc04
.BR d ,
Packit 7cfc04
.BR i ,
Packit 7cfc04
.BR o ,
Packit 7cfc04
.BR u ,
Packit 7cfc04
.BR x ,
Packit 7cfc04
or
Packit 7cfc04
.BR X
Packit 7cfc04
conversion specifier applies to an
Packit 7cfc04
.BR intmax_t
Packit 7cfc04
or
Packit 7cfc04
.BR uintmax_t
Packit 7cfc04
argument; or that a following
Packit 7cfc04
.BR n
Packit 7cfc04
conversion specifier applies to a pointer to an
Packit 7cfc04
.BR intmax_t
Packit 7cfc04
argument.
Packit 7cfc04
.IP "\fRz\fR" 8
Packit 7cfc04
Specifies that a following
Packit 7cfc04
.BR d ,
Packit 7cfc04
.BR i ,
Packit 7cfc04
.BR o ,
Packit 7cfc04
.BR u ,
Packit 7cfc04
.BR x ,
Packit 7cfc04
or
Packit 7cfc04
.BR X
Packit 7cfc04
conversion specifier applies to a
Packit 7cfc04
.BR size_t
Packit 7cfc04
or the corresponding signed integer type argument; or that a following
Packit 7cfc04
.BR n
Packit 7cfc04
conversion specifier applies to a pointer to a signed integer type
Packit 7cfc04
corresponding to a
Packit 7cfc04
.BR size_t
Packit 7cfc04
argument.
Packit 7cfc04
.IP "\fRt\fR" 8
Packit 7cfc04
Specifies that a following
Packit 7cfc04
.BR d ,
Packit 7cfc04
.BR i ,
Packit 7cfc04
.BR o ,
Packit 7cfc04
.BR u ,
Packit 7cfc04
.BR x ,
Packit 7cfc04
or
Packit 7cfc04
.BR X
Packit 7cfc04
conversion specifier applies to a
Packit 7cfc04
.BR ptrdiff_t
Packit 7cfc04
or the corresponding
Packit 7cfc04
.BR unsigned
Packit 7cfc04
type argument; or that a following
Packit 7cfc04
.BR n
Packit 7cfc04
conversion specifier applies to a pointer to a
Packit 7cfc04
.BR ptrdiff_t
Packit 7cfc04
argument.
Packit 7cfc04
.IP "\fRL\fR" 8
Packit 7cfc04
Specifies that a following
Packit 7cfc04
.BR a ,
Packit 7cfc04
.BR A ,
Packit 7cfc04
.BR e ,
Packit 7cfc04
.BR E ,
Packit 7cfc04
.BR f ,
Packit 7cfc04
.BR F ,
Packit 7cfc04
.BR g ,
Packit 7cfc04
or
Packit 7cfc04
.BR G
Packit 7cfc04
conversion specifier applies to a
Packit 7cfc04
.BR "long double"
Packit 7cfc04
argument.
Packit 7cfc04
.P
Packit 7cfc04
If a length modifier appears with any conversion specifier other than
Packit 7cfc04
as specified above, the behavior is undefined.
Packit 7cfc04
.P
Packit 7cfc04
The conversion specifiers and their meanings are:
Packit 7cfc04
.IP "\fRd\fR,\ \fRi\fR" 8
Packit 7cfc04
The
Packit 7cfc04
.BR int
Packit 7cfc04
argument shall be converted to a signed decimal in the style
Packit 7cfc04
\fR"[\(mi]\fIdddd\fR"\fR. The precision specifies the minimum number of
Packit 7cfc04
digits to appear; if the value being converted can be represented in
Packit 7cfc04
fewer digits, it shall be expanded with leading zeros. The default
Packit 7cfc04
precision is 1. The result of converting zero with an explicit
Packit 7cfc04
precision of zero shall be no characters.
Packit 7cfc04
.IP "\fRo\fP" 8
Packit 7cfc04
The
Packit 7cfc04
.BR unsigned
Packit 7cfc04
argument shall be converted to unsigned octal format in the style
Packit 7cfc04
\fR"\fIdddd\fR"\fR. The precision specifies the minimum number of
Packit 7cfc04
digits to appear; if the value being converted can be represented in
Packit 7cfc04
fewer digits, it shall be expanded with leading zeros. The default
Packit 7cfc04
precision is 1. The result of converting zero with an explicit
Packit 7cfc04
precision of zero shall be no characters.
Packit 7cfc04
.IP "\fRu\fP" 8
Packit 7cfc04
The
Packit 7cfc04
.BR unsigned
Packit 7cfc04
argument shall be converted to unsigned decimal format in the style
Packit 7cfc04
\fR"\fIdddd\fR"\fR. The precision specifies the minimum number of
Packit 7cfc04
digits to appear; if the value being converted can be represented in
Packit 7cfc04
fewer digits, it shall be expanded with leading zeros. The default
Packit 7cfc04
precision is 1. The result of converting zero with an explicit
Packit 7cfc04
precision of zero shall be no characters.
Packit 7cfc04
.IP "\fRx\fP" 8
Packit 7cfc04
The
Packit 7cfc04
.BR unsigned
Packit 7cfc04
argument shall be converted to unsigned hexadecimal format in the
Packit 7cfc04
style \fR"\fIdddd\fR"\fR; the letters
Packit 7cfc04
.BR \(dqabcdef\(dq 
Packit 7cfc04
are used. The precision specifies the minimum number of digits to
Packit 7cfc04
appear; if the value being converted can be represented in fewer
Packit 7cfc04
digits, it shall be expanded with leading zeros. The default precision
Packit 7cfc04
is 1. The result of converting zero with an explicit precision of zero
Packit 7cfc04
shall be no characters.
Packit 7cfc04
.IP "\fRX\fP" 8
Packit 7cfc04
Equivalent to the
Packit 7cfc04
.BR x
Packit 7cfc04
conversion specifier, except that letters
Packit 7cfc04
.BR \(dqABCDEF\(dq 
Packit 7cfc04
are used instead of
Packit 7cfc04
.BR \(dqabcdef\(dq .
Packit 7cfc04
.IP "\fRf\fR,\ \fRF\fR" 8
Packit 7cfc04
The
Packit 7cfc04
.BR double
Packit 7cfc04
argument shall be converted to decimal notation in the style
Packit 7cfc04
\fR"[\(mi]\fIddd\fR.\fIddd\fR"\fR, where the number of digits after the
Packit 7cfc04
radix character is equal to the precision specification. If the
Packit 7cfc04
precision is missing, it shall be taken as 6; if the precision is
Packit 7cfc04
explicitly zero and no
Packit 7cfc04
.BR '#' 
Packit 7cfc04
flag is present, no radix character shall appear. If a radix character
Packit 7cfc04
appears, at least one digit appears before it. The low-order digit
Packit 7cfc04
shall be rounded in an implementation-defined manner.
Packit 7cfc04
.RS 8 
Packit 7cfc04
.P
Packit 7cfc04
A
Packit 7cfc04
.BR double
Packit 7cfc04
argument representing an infinity shall be converted in one of the
Packit 7cfc04
styles
Packit 7cfc04
.BR \(dq[\(mi]inf\(dq 
Packit 7cfc04
or
Packit 7cfc04
.BR \(dq[\(mi]infinity\(dq ;
Packit 7cfc04
which style is implementation-defined. A
Packit 7cfc04
.BR double
Packit 7cfc04
argument representing a NaN shall be converted in one of the styles
Packit 7cfc04
\fR"[\(mi]nan(\fIn-char-sequence\fR)"\fR or
Packit 7cfc04
.BR \(dq[\(mi]nan\(dq ;
Packit 7cfc04
which style, and the meaning of any
Packit 7cfc04
.IR n-char-sequence ,
Packit 7cfc04
is implementation-defined. The
Packit 7cfc04
.BR F
Packit 7cfc04
conversion specifier produces
Packit 7cfc04
.BR \(dqINF\(dq ,
Packit 7cfc04
.BR \(dqINFINITY\(dq ,
Packit 7cfc04
or
Packit 7cfc04
.BR \(dqNAN\(dq 
Packit 7cfc04
instead of
Packit 7cfc04
.BR \(dqinf\(dq ,
Packit 7cfc04
.BR \(dqinfinity\(dq ,
Packit 7cfc04
or
Packit 7cfc04
.BR \(dqnan\(dq ,
Packit 7cfc04
respectively.
Packit 7cfc04
.RE
Packit 7cfc04
.IP "\fRe\fR,\ \fRE\fR" 8
Packit 7cfc04
The
Packit 7cfc04
.BR double
Packit 7cfc04
argument shall be converted in the style
Packit 7cfc04
\fR"[\(mi]\fId\fR.\fIddd\fRe\(+-\fIdd\fR"\fR, where there is one digit
Packit 7cfc04
before the radix character (which is non-zero if the argument is
Packit 7cfc04
non-zero) and the number of digits after it is equal to the precision;
Packit 7cfc04
if the precision is missing, it shall be taken as 6; if the precision
Packit 7cfc04
is zero and no
Packit 7cfc04
.BR '#' 
Packit 7cfc04
flag is present, no radix character shall appear. The low-order digit
Packit 7cfc04
shall be rounded in an implementation-defined manner. The
Packit 7cfc04
.BR E
Packit 7cfc04
conversion specifier shall produce a number with
Packit 7cfc04
.BR 'E' 
Packit 7cfc04
instead of
Packit 7cfc04
.BR 'e' 
Packit 7cfc04
introducing the exponent. The exponent shall always contain at least
Packit 7cfc04
two digits. If the value is zero, the exponent shall be zero.
Packit 7cfc04
.RS 8 
Packit 7cfc04
.P
Packit 7cfc04
A
Packit 7cfc04
.BR double
Packit 7cfc04
argument representing an infinity or NaN shall be converted in
Packit 7cfc04
the style of an
Packit 7cfc04
.BR f
Packit 7cfc04
or
Packit 7cfc04
.BR F
Packit 7cfc04
conversion specifier.
Packit 7cfc04
.RE
Packit 7cfc04
.IP "\fRg\fR,\ \fRG\fR" 8
Packit 7cfc04
The
Packit 7cfc04
.BR double
Packit 7cfc04
argument representing a floating-point number shall be converted in the
Packit 7cfc04
style
Packit 7cfc04
.BR f
Packit 7cfc04
or
Packit 7cfc04
.BR e
Packit 7cfc04
(or in the style
Packit 7cfc04
.BR F
Packit 7cfc04
or
Packit 7cfc04
.BR E
Packit 7cfc04
in the case of a
Packit 7cfc04
.BR G
Packit 7cfc04
conversion specifier), depending on the value converted and the precision.
Packit 7cfc04
Let
Packit 7cfc04
.BR P
Packit 7cfc04
equal the precision if non-zero, 6 if the precision is omitted, or 1 if the
Packit 7cfc04
precision is zero. Then, if a conversion with style
Packit 7cfc04
.BR E
Packit 7cfc04
would have an exponent of
Packit 7cfc04
.IR X :
Packit 7cfc04
.RS 8 
Packit 7cfc04
.IP -- 4
Packit 7cfc04
If
Packit 7cfc04
.BR P >\c
Packit 7cfc04
.IR X \(>=\(mi4,
Packit 7cfc04
the conversion shall be with style
Packit 7cfc04
.BR f
Packit 7cfc04
(or
Packit 7cfc04
.BR F )
Packit 7cfc04
and precision
Packit 7cfc04
.BR P \(mi(\c
Packit 7cfc04
.IR X +1).
Packit 7cfc04
.IP -- 4
Packit 7cfc04
Otherwise, the conversion shall be with style
Packit 7cfc04
.BR e
Packit 7cfc04
(or
Packit 7cfc04
.BR E )
Packit 7cfc04
and precision
Packit 7cfc04
.BR P \(mi1.
Packit 7cfc04
.P
Packit 7cfc04
Finally, unless the
Packit 7cfc04
.BR '#' 
Packit 7cfc04
flag is used, any trailing zeros shall be removed from the fractional
Packit 7cfc04
portion of the result and the decimal-point character shall be removed
Packit 7cfc04
if there is no fractional portion remaining.
Packit 7cfc04
.P
Packit 7cfc04
A
Packit 7cfc04
.BR double
Packit 7cfc04
argument representing an infinity or NaN shall be converted in the
Packit 7cfc04
style of an
Packit 7cfc04
.BR f
Packit 7cfc04
or
Packit 7cfc04
.BR F
Packit 7cfc04
conversion specifier.
Packit 7cfc04
.RE
Packit 7cfc04
.IP "\fRa\fR,\ \fRA\fR" 8
Packit 7cfc04
A
Packit 7cfc04
.BR double
Packit 7cfc04
argument representing a floating-point number shall be converted in the
Packit 7cfc04
style \fR"[\(mi]0x\fIh\fR.\fIhhhh\fRp\(+-\fId\fR"\fR, where there is
Packit 7cfc04
one hexadecimal digit (which shall be non-zero if the argument is a
Packit 7cfc04
normalized floating-point number and is otherwise unspecified) before
Packit 7cfc04
the decimal-point character and the number of hexadecimal digits after
Packit 7cfc04
it is equal to the precision; if the precision is missing and FLT_RADIX
Packit 7cfc04
is a power of 2, then the precision shall be sufficient for an exact
Packit 7cfc04
representation of the value; if the precision is missing and FLT_RADIX
Packit 7cfc04
is not a power of 2, then the precision shall be sufficient to
Packit 7cfc04
distinguish values of type
Packit 7cfc04
.BR double ,
Packit 7cfc04
except that trailing zeros may be omitted; if the precision is zero and
Packit 7cfc04
the
Packit 7cfc04
.BR '#' 
Packit 7cfc04
flag is not specified, no decimal-point character shall appear. The
Packit 7cfc04
letters
Packit 7cfc04
.BR \(dqabcdef\(dq 
Packit 7cfc04
shall be used for
Packit 7cfc04
.BR a
Packit 7cfc04
conversion and the letters
Packit 7cfc04
.BR \(dqABCDEF\(dq 
Packit 7cfc04
for
Packit 7cfc04
.BR A
Packit 7cfc04
conversion. The
Packit 7cfc04
.BR A
Packit 7cfc04
conversion specifier produces a number with
Packit 7cfc04
.BR 'X' 
Packit 7cfc04
and
Packit 7cfc04
.BR 'P' 
Packit 7cfc04
instead of
Packit 7cfc04
.BR 'x' 
Packit 7cfc04
and
Packit 7cfc04
.BR 'p' .
Packit 7cfc04
The exponent shall always contain at least one digit, and only as many
Packit 7cfc04
more digits as necessary to represent the decimal exponent of 2. If the
Packit 7cfc04
value is zero, the exponent shall be zero.
Packit 7cfc04
.RS 8 
Packit 7cfc04
.P
Packit 7cfc04
A
Packit 7cfc04
.BR double
Packit 7cfc04
argument representing an infinity or NaN shall be converted in the
Packit 7cfc04
style of an
Packit 7cfc04
.BR f
Packit 7cfc04
or
Packit 7cfc04
.BR F
Packit 7cfc04
conversion specifier.
Packit 7cfc04
.RE
Packit 7cfc04
.IP "\fRc\fP" 8
Packit 7cfc04
The
Packit 7cfc04
.BR int
Packit 7cfc04
argument shall be converted to an
Packit 7cfc04
.BR "unsigned char" ,
Packit 7cfc04
and the resulting byte shall be written.
Packit 7cfc04
.RS 8 
Packit 7cfc04
.P
Packit 7cfc04
If an
Packit 7cfc04
.BR l
Packit 7cfc04
(ell) qualifier is present, the
Packit 7cfc04
.BR wint_t
Packit 7cfc04
argument shall be converted as if by an
Packit 7cfc04
.BR ls
Packit 7cfc04
conversion specification with no precision and an argument that points
Packit 7cfc04
to a two-element array of type
Packit 7cfc04
.BR wchar_t ,
Packit 7cfc04
the first element of which contains the
Packit 7cfc04
.BR wint_t
Packit 7cfc04
argument to the
Packit 7cfc04
.BR ls
Packit 7cfc04
conversion specification and the second element contains a null wide
Packit 7cfc04
character.
Packit 7cfc04
.RE
Packit 7cfc04
.IP "\fRs\fP" 8
Packit 7cfc04
The argument shall be a pointer to an array of
Packit 7cfc04
.BR char .
Packit 7cfc04
Bytes from the array shall be written up to (but not including) any
Packit 7cfc04
terminating null byte. If the precision is specified, no more than that
Packit 7cfc04
many bytes shall be written. If the precision is not specified or is
Packit 7cfc04
greater than the size of the array, the application shall ensure that
Packit 7cfc04
the array contains a null byte.
Packit 7cfc04
.RS 8 
Packit 7cfc04
.P
Packit 7cfc04
If an
Packit 7cfc04
.BR l
Packit 7cfc04
(ell) qualifier is present, the argument shall be a pointer to an array
Packit 7cfc04
of type
Packit 7cfc04
.BR wchar_t .
Packit 7cfc04
Wide characters from the array shall be converted to characters (each
Packit 7cfc04
as if by a call to the
Packit 7cfc04
\fIwcrtomb\fR()
Packit 7cfc04
function, with the conversion state described by an
Packit 7cfc04
.BR mbstate_t
Packit 7cfc04
object initialized to zero before the first wide character is
Packit 7cfc04
converted) up to and including a terminating null wide character. The
Packit 7cfc04
resulting characters shall be written up to (but not including) the
Packit 7cfc04
terminating null character (byte). If no precision is specified, the
Packit 7cfc04
application shall ensure that the array contains a null wide character.
Packit 7cfc04
If a precision is specified, no more than that many characters (bytes)
Packit 7cfc04
shall be written (including shift sequences, if any), and the array
Packit 7cfc04
shall contain a null wide character if, to equal the character sequence
Packit 7cfc04
length given by the precision, the function would need to access a wide
Packit 7cfc04
character one past the end of the array. In no case shall a partial
Packit 7cfc04
character be written.
Packit 7cfc04
.RE
Packit 7cfc04
.IP "\fRp\fP" 8
Packit 7cfc04
The argument shall be a pointer to
Packit 7cfc04
.BR void .
Packit 7cfc04
The value of the pointer is converted to a sequence of printable
Packit 7cfc04
characters, in an implementation-defined manner.
Packit 7cfc04
.IP "\fRn\fP" 8
Packit 7cfc04
The argument shall be a pointer to an integer into which is written the
Packit 7cfc04
number of bytes written to the output so far by this call to one of the
Packit 7cfc04
\fIfprintf\fR()
Packit 7cfc04
functions. No argument is converted.
Packit 7cfc04
.IP "\fRC\fP" 8
Packit 7cfc04
Equivalent to
Packit 7cfc04
.BR lc .
Packit 7cfc04
.IP "\fRS\fP" 8
Packit 7cfc04
Equivalent to
Packit 7cfc04
.BR ls .
Packit 7cfc04
.IP "\fR%\fR" 8
Packit 7cfc04
Print a
Packit 7cfc04
.BR '%' 
Packit 7cfc04
character; no argument is converted. The complete conversion
Packit 7cfc04
specification shall be
Packit 7cfc04
.BR %% .
Packit 7cfc04
.P
Packit 7cfc04
If a conversion specification does not match one of the above forms,
Packit 7cfc04
the behavior is undefined. If any argument is not the correct type for
Packit 7cfc04
the corresponding conversion specification, the behavior is undefined.
Packit 7cfc04
.P
Packit 7cfc04
In no case shall a nonexistent or small field width cause truncation of
Packit 7cfc04
a field; if the result of a conversion is wider than the field width,
Packit 7cfc04
the field shall be expanded to contain the conversion result.
Packit 7cfc04
Characters generated by
Packit 7cfc04
\fIfprintf\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIprintf\fR()
Packit 7cfc04
are printed as if
Packit 7cfc04
\fIfputc\fR()
Packit 7cfc04
had been called.
Packit 7cfc04
.P
Packit 7cfc04
For the
Packit 7cfc04
.BR a
Packit 7cfc04
and
Packit 7cfc04
.BR A
Packit 7cfc04
conversion specifiers, if FLT_RADIX is a power of 2, the value shall be
Packit 7cfc04
correctly rounded to a hexadecimal floating number with the given
Packit 7cfc04
precision.
Packit 7cfc04
.P
Packit 7cfc04
For
Packit 7cfc04
.BR a
Packit 7cfc04
and
Packit 7cfc04
.BR A
Packit 7cfc04
conversions, if FLT_RADIX is not a power of 2 and the result is not
Packit 7cfc04
exactly representable in the given precision, the result should be one
Packit 7cfc04
of the two adjacent numbers in hexadecimal floating style with the
Packit 7cfc04
given precision, with the extra stipulation that the error should have
Packit 7cfc04
a correct sign for the current rounding direction.
Packit 7cfc04
.P
Packit 7cfc04
For the
Packit 7cfc04
.BR e ,
Packit 7cfc04
.BR E ,
Packit 7cfc04
.BR f ,
Packit 7cfc04
.BR F ,
Packit 7cfc04
.BR g ,
Packit 7cfc04
and
Packit 7cfc04
.BR G
Packit 7cfc04
conversion specifiers, if the number of significant decimal digits is
Packit 7cfc04
at most DECIMAL_DIG, then the result should be correctly rounded. If
Packit 7cfc04
the number of significant decimal digits is more than DECIMAL_DIG but
Packit 7cfc04
the source value is exactly representable with DECIMAL_DIG digits, then
Packit 7cfc04
the result should be an exact representation with trailing zeros.
Packit 7cfc04
Otherwise, the source value is bounded by two adjacent decimal strings
Packit 7cfc04
.IR L
Packit 7cfc04
<
Packit 7cfc04
.IR U ,
Packit 7cfc04
both having DECIMAL_DIG significant digits; the value of the resultant
Packit 7cfc04
decimal string
Packit 7cfc04
.IR D
Packit 7cfc04
should satisfy
Packit 7cfc04
.IR L
Packit 7cfc04
<=
Packit 7cfc04
.IR D
Packit 7cfc04
<=
Packit 7cfc04
.IR U ,
Packit 7cfc04
with the extra stipulation that the error should have a correct sign
Packit 7cfc04
for the current rounding direction.
Packit 7cfc04
.P
Packit 7cfc04
The last data modification and last file status change timestamps
Packit 7cfc04
of the file shall be marked for update:
Packit 7cfc04
.IP " 1." 4
Packit 7cfc04
Between the call to a successful execution of
Packit 7cfc04
\fIfprintf\fR()
Packit 7cfc04
or
Packit 7cfc04
\fIprintf\fR()
Packit 7cfc04
and the next successful completion of a call to
Packit 7cfc04
\fIfflush\fR()
Packit 7cfc04
or
Packit 7cfc04
\fIfclose\fR()
Packit 7cfc04
on the same stream or a call to
Packit 7cfc04
\fIexit\fR()
Packit 7cfc04
or
Packit 7cfc04
\fIabort\fR()
Packit 7cfc04
.IP " 2." 4
Packit 7cfc04
Upon successful completion of a call to
Packit 7cfc04
\fIdprintf\fR()
Packit 7cfc04
.SH "RETURN VALUE"
Packit 7cfc04
Upon successful completion, the
Packit 7cfc04
\fIdprintf\fR(),
Packit 7cfc04
\fIfprintf\fR(),
Packit 7cfc04
and
Packit 7cfc04
\fIprintf\fR()
Packit 7cfc04
functions shall return the number of bytes transmitted.
Packit 7cfc04
.P
Packit 7cfc04
Upon successful completion, the
Packit 7cfc04
\fIsprintf\fR()
Packit 7cfc04
function shall return the number of bytes written to
Packit 7cfc04
.IR s ,
Packit 7cfc04
excluding the terminating null byte.
Packit 7cfc04
.P
Packit 7cfc04
Upon successful completion, the
Packit 7cfc04
\fIsnprintf\fR()
Packit 7cfc04
function shall return the number of bytes that would be written to
Packit 7cfc04
.IR s
Packit 7cfc04
had
Packit 7cfc04
.IR n
Packit 7cfc04
been sufficiently large excluding the terminating null byte.
Packit 7cfc04
.P
Packit 7cfc04
If an output error was encountered, these functions shall return a
Packit 7cfc04
negative value
Packit 7cfc04
and set
Packit 7cfc04
.IR errno
Packit 7cfc04
to indicate the error.
Packit 7cfc04
.P
Packit 7cfc04
If the value of
Packit 7cfc04
.IR n
Packit 7cfc04
is zero on a call to
Packit 7cfc04
\fIsnprintf\fR(),
Packit 7cfc04
nothing shall be written, the number of bytes that would have been
Packit 7cfc04
written had
Packit 7cfc04
.IR n
Packit 7cfc04
been sufficiently large excluding the terminating null shall be
Packit 7cfc04
returned, and
Packit 7cfc04
.IR s
Packit 7cfc04
may be a null pointer.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
For the conditions under which
Packit 7cfc04
\fIdprintf\fR(),
Packit 7cfc04
\fIfprintf\fR(),
Packit 7cfc04
and
Packit 7cfc04
\fIprintf\fR()
Packit 7cfc04
fail and may fail, refer to
Packit 7cfc04
.IR "\fIfputc\fR\^(\|)"
Packit 7cfc04
or
Packit 7cfc04
.IR "\fIfputwc\fR\^(\|)".
Packit 7cfc04
.P
Packit 7cfc04
In addition, all forms of
Packit 7cfc04
\fIfprintf\fR()
Packit 7cfc04
shall fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR EILSEQ
Packit 7cfc04
A wide-character code that does not correspond to a valid character
Packit 7cfc04
has been detected.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EOVERFLOW
Packit 7cfc04
The value to be returned is greater than
Packit 7cfc04
{INT_MAX}.
Packit 7cfc04
.P
Packit 7cfc04
In addition, all forms of
Packit 7cfc04
\fIfprintf\fR()
Packit 7cfc04
may fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR EINVAL
Packit 7cfc04
There are insufficient arguments.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
\fIdprintf\fR()
Packit 7cfc04
function may fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR EBADF
Packit 7cfc04
The
Packit 7cfc04
.IR fildes
Packit 7cfc04
argument is not a valid file descriptor.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
\fIdprintf\fR(),
Packit 7cfc04
\fIfprintf\fR(),
Packit 7cfc04
and
Packit 7cfc04
\fIprintf\fR()
Packit 7cfc04
functions may fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOMEM
Packit 7cfc04
Insufficient storage space is available.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
\fIsnprintf\fR()
Packit 7cfc04
function shall fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR EOVERFLOW
Packit 7cfc04
The value of
Packit 7cfc04
.IR n
Packit 7cfc04
is greater than
Packit 7cfc04
{INT_MAX}.
Packit 7cfc04
.LP
Packit 7cfc04
.IR "The following sections are informative."
Packit 7cfc04
.SH "EXAMPLES"
Packit 7cfc04
.SS "Printing Language-Independent Date and Time"
Packit 7cfc04
.P
Packit 7cfc04
The following statement can be used to print date and time using a
Packit 7cfc04
language-independent format:
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
printf(format, weekday, month, day, hour, min);
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.P
Packit 7cfc04
For American usage,
Packit 7cfc04
.IR format
Packit 7cfc04
could be a pointer to the following string:
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
"%s, %s %d, %d:%.2d\en"
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.P
Packit 7cfc04
This example would produce the following message:
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
Sunday, July 3, 10:02
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.P
Packit 7cfc04
For German usage,
Packit 7cfc04
.IR format
Packit 7cfc04
could be a pointer to the following string:
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
"%1$s, %3$d. %2$s, %4$d:%5$.2d\en"
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.P
Packit 7cfc04
This definition of
Packit 7cfc04
.IR format
Packit 7cfc04
would produce the following message:
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
Sonntag, 3. Juli, 10:02
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SS "Printing File Information"
Packit 7cfc04
.P
Packit 7cfc04
The following example prints information about the type, permissions,
Packit 7cfc04
and number of links of a specific file in a directory.
Packit 7cfc04
.P
Packit 7cfc04
The first two calls to
Packit 7cfc04
\fIprintf\fR()
Packit 7cfc04
use data decoded from a previous
Packit 7cfc04
\fIstat\fR()
Packit 7cfc04
call. The user-defined
Packit 7cfc04
\fIstrperm\fR()
Packit 7cfc04
function shall return a string similar to the one at the beginning of the
Packit 7cfc04
output for the following command:
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
ls \(mil
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.P
Packit 7cfc04
The next call to
Packit 7cfc04
\fIprintf\fR()
Packit 7cfc04
outputs the owner's name if it is found using
Packit 7cfc04
\fIgetpwuid\fR();
Packit 7cfc04
the
Packit 7cfc04
\fIgetpwuid\fR()
Packit 7cfc04
function shall return a
Packit 7cfc04
.BR passwd
Packit 7cfc04
structure from which the name of the user is extracted. If the user
Packit 7cfc04
name is not found, the program instead prints out the numeric value of
Packit 7cfc04
the user ID.
Packit 7cfc04
.P
Packit 7cfc04
The next call prints out the group name if it is found using
Packit 7cfc04
\fIgetgrgid\fR();
Packit 7cfc04
\fIgetgrgid\fR()
Packit 7cfc04
is very similar to
Packit 7cfc04
\fIgetpwuid\fR()
Packit 7cfc04
except that it shall return group information based on the group number.
Packit 7cfc04
Once again, if the group is not found, the program prints the numeric
Packit 7cfc04
value of the group for the entry.
Packit 7cfc04
.P
Packit 7cfc04
The final call to
Packit 7cfc04
\fIprintf\fR()
Packit 7cfc04
prints the size of the file.
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
#include <sys/types.h>
Packit 7cfc04
#include <pwd.h>
Packit 7cfc04
#include <grp.h>
Packit 7cfc04
.P
Packit 7cfc04
char *strperm (mode_t);
Packit 7cfc04
\&...
Packit 7cfc04
struct stat statbuf;
Packit 7cfc04
struct passwd *pwd;
Packit 7cfc04
struct group *grp;
Packit 7cfc04
\&...
Packit 7cfc04
printf("%10.10s", strperm (statbuf.st_mode));
Packit 7cfc04
printf("%4d", statbuf.st_nlink);
Packit 7cfc04
.P
Packit 7cfc04
if ((pwd = getpwuid(statbuf.st_uid)) != NULL)
Packit 7cfc04
    printf(" %\(mi8.8s", pwd->pw_name);
Packit 7cfc04
else
Packit 7cfc04
    printf(" %\(mi8ld", (long) statbuf.st_uid);
Packit 7cfc04
.P
Packit 7cfc04
if ((grp = getgrgid(statbuf.st_gid)) != NULL)
Packit 7cfc04
    printf(" %\(mi8.8s", grp->gr_name);
Packit 7cfc04
else
Packit 7cfc04
    printf(" %\(mi8ld", (long) statbuf.st_gid);
Packit 7cfc04
.P
Packit 7cfc04
printf("%9jd", (intmax_t) statbuf.st_size);
Packit 7cfc04
\&...
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SS "Printing a Localized Date String"
Packit 7cfc04
.P
Packit 7cfc04
The following example gets a localized date string. The
Packit 7cfc04
\fInl_langinfo\fR()
Packit 7cfc04
function shall return the localized date string, which specifies the
Packit 7cfc04
order and layout of the date. The
Packit 7cfc04
\fIstrftime\fR()
Packit 7cfc04
function takes this information and, using the
Packit 7cfc04
.BR tm
Packit 7cfc04
structure for values, places the date and time information into
Packit 7cfc04
.IR datestring .
Packit 7cfc04
The
Packit 7cfc04
\fIprintf\fR()
Packit 7cfc04
function then outputs
Packit 7cfc04
.IR datestring
Packit 7cfc04
and the name of the entry.
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
#include <time.h>
Packit 7cfc04
#include <langinfo.h>
Packit 7cfc04
\&...
Packit 7cfc04
struct dirent *dp;
Packit 7cfc04
struct tm *tm;
Packit 7cfc04
char datestring[256];
Packit 7cfc04
\&...
Packit 7cfc04
strftime(datestring, sizeof(datestring), nl_langinfo (D_T_FMT), tm);
Packit 7cfc04
.P
Packit 7cfc04
printf(" %s %s\en", datestring, dp->d_name);
Packit 7cfc04
\&...
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SS "Printing Error Information"
Packit 7cfc04
.P
Packit 7cfc04
The following example uses
Packit 7cfc04
\fIfprintf\fR()
Packit 7cfc04
to write error information to standard error.
Packit 7cfc04
.P
Packit 7cfc04
In the first group of calls, the program tries to open the password
Packit 7cfc04
lock file named
Packit 7cfc04
.BR LOCKFILE .
Packit 7cfc04
If the file already exists, this is an error, as indicated by the
Packit 7cfc04
O_EXCL flag on the
Packit 7cfc04
\fIopen\fR()
Packit 7cfc04
function. If the call fails, the program assumes that someone else is
Packit 7cfc04
updating the password file, and the program exits.
Packit 7cfc04
.P
Packit 7cfc04
The next group of calls saves a new password file as the current
Packit 7cfc04
password file by creating a link between
Packit 7cfc04
.BR LOCKFILE
Packit 7cfc04
and the new password file
Packit 7cfc04
.BR PASSWDFILE .
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
#include <sys/types.h>
Packit 7cfc04
#include <sys/stat.h>
Packit 7cfc04
#include <fcntl.h>
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
#include <stdlib.h>
Packit 7cfc04
#include <unistd.h>
Packit 7cfc04
#include <string.h>
Packit 7cfc04
#include <errno.h>
Packit 7cfc04
.P
Packit 7cfc04
#define LOCKFILE "/etc/ptmp"
Packit 7cfc04
#define PASSWDFILE "/etc/passwd"
Packit 7cfc04
\&...
Packit 7cfc04
int pfd;
Packit 7cfc04
\&...
Packit 7cfc04
if ((pfd = open(LOCKFILE, O_WRONLY | O_CREAT | O_EXCL,
Packit 7cfc04
    S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == \(mi1)
Packit 7cfc04
{
Packit 7cfc04
    fprintf(stderr, "Cannot open /etc/ptmp. Try again later.\en");
Packit 7cfc04
    exit(1);
Packit 7cfc04
}
Packit 7cfc04
\&...
Packit 7cfc04
if (link(LOCKFILE,PASSWDFILE) == -1) {
Packit 7cfc04
    fprintf(stderr, "Link error: %s\en", strerror(errno));
Packit 7cfc04
    exit(1);
Packit 7cfc04
}
Packit 7cfc04
\&...
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SS "Printing Usage Information"
Packit 7cfc04
.P
Packit 7cfc04
The following example checks to make sure the program has the necessary
Packit 7cfc04
arguments, and uses
Packit 7cfc04
\fIfprintf\fR()
Packit 7cfc04
to print usage information if the expected number of arguments is not
Packit 7cfc04
present.
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
#include <stdlib.h>
Packit 7cfc04
\&...
Packit 7cfc04
char *Options = "hdbtl";
Packit 7cfc04
\&...
Packit 7cfc04
if (argc < 2) {
Packit 7cfc04
    fprintf(stderr, "Usage: %s -%s 
Packit 7cfc04
}
Packit 7cfc04
\&...
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SS "Formatting a Decimal String"
Packit 7cfc04
.P
Packit 7cfc04
The following example prints a key and data pair on
Packit 7cfc04
.IR stdout .
Packit 7cfc04
Note use of the
Packit 7cfc04
<asterisk>
Packit 7cfc04
(\c
Packit 7cfc04
.BR '*' )
Packit 7cfc04
in the format string; this ensures the correct number of decimal places
Packit 7cfc04
for the element based on the number of elements requested.
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
\&...
Packit 7cfc04
long i;
Packit 7cfc04
char *keystr;
Packit 7cfc04
int elementlen, len;
Packit 7cfc04
\&...
Packit 7cfc04
while (len < elementlen) {
Packit 7cfc04
\&...
Packit 7cfc04
    printf("%s Element%0*ld\en", keystr, elementlen, i);
Packit 7cfc04
\&...
Packit 7cfc04
}
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SS "Creating a Pathname"
Packit 7cfc04
.P
Packit 7cfc04
The following example creates a pathname using information from a previous
Packit 7cfc04
\fIgetpwnam\fR()
Packit 7cfc04
function that returned the password database entry of the user.
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
#include <stdint.h>
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
#include <stdlib.h>
Packit 7cfc04
#include <string.h>
Packit 7cfc04
#include <sys/types.h>
Packit 7cfc04
#include <unistd.h>
Packit 7cfc04
\&...
Packit 7cfc04
char *pathname;
Packit 7cfc04
struct passwd *pw;
Packit 7cfc04
size_t len;
Packit 7cfc04
\&...
Packit 7cfc04
// digits required for pid_t is number of bits times
Packit 7cfc04
// log2(10) = approx 10/33
Packit 7cfc04
len = strlen(pw->pw_dir) + 1 + 1+(sizeof(pid_t)*80+32)/33 +
Packit 7cfc04
    sizeof ".out";
Packit 7cfc04
pathname = malloc(len);
Packit 7cfc04
if (pathname != NULL)
Packit 7cfc04
{
Packit 7cfc04
    snprintf(pathname, len, "%s/%jd.out", pw->pw_dir,
Packit 7cfc04
        (intmax_t)getpid());
Packit 7cfc04
    ...
Packit 7cfc04
}
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SS "Reporting an Event"
Packit 7cfc04
.P
Packit 7cfc04
The following example loops until an event has timed out. The
Packit 7cfc04
\fIpause\fR()
Packit 7cfc04
function waits forever unless it receives a signal. The
Packit 7cfc04
\fIfprintf\fR()
Packit 7cfc04
statement should never occur due to the possible return values of
Packit 7cfc04
\fIpause\fR().
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
#include <unistd.h>
Packit 7cfc04
#include <string.h>
Packit 7cfc04
#include <errno.h>
Packit 7cfc04
\&...
Packit 7cfc04
while (!event_complete) {
Packit 7cfc04
\&...
Packit 7cfc04
    if (pause() != \(mi1 || errno != EINTR)
Packit 7cfc04
        fprintf(stderr, "pause: unknown error: %s\en", strerror(errno));
Packit 7cfc04
}
Packit 7cfc04
\&...
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SS "Printing Monetary Information"
Packit 7cfc04
.P
Packit 7cfc04
The following example uses
Packit 7cfc04
\fIstrfmon\fR()
Packit 7cfc04
to convert a number and store it as a formatted monetary string named
Packit 7cfc04
.IR convbuf .
Packit 7cfc04
If the first number is printed, the program prints the format and the
Packit 7cfc04
description; otherwise, it just prints the number.
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
#include <monetary.h>
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
\&...
Packit 7cfc04
struct tblfmt {
Packit 7cfc04
    char *format;
Packit 7cfc04
    char *description;
Packit 7cfc04
};
Packit 7cfc04
.P
Packit 7cfc04
struct tblfmt table[] = {
Packit 7cfc04
    { "%n", "default formatting" },
Packit 7cfc04
    { "%11n", "right align within an 11 character field" },
Packit 7cfc04
    { "%#5n", "aligned columns for values up to 99\|999" },
Packit 7cfc04
    { "%=*#5n", "specify a fill character" },
Packit 7cfc04
    { "%=0#5n", "fill characters do not use grouping" },
Packit 7cfc04
    { "%^#5n", "disable the grouping separator" },
Packit 7cfc04
    { "%^#5.0n", "round off to whole units" },
Packit 7cfc04
    { "%^#5.4n", "increase the precision" },
Packit 7cfc04
    { "%(#5n", "use an alternative pos/neg style" },
Packit 7cfc04
    { "%!(#5n", "disable the currency symbol" },
Packit 7cfc04
};
Packit 7cfc04
\&...
Packit 7cfc04
float input[3];
Packit 7cfc04
int i, j;
Packit 7cfc04
char convbuf[100];
Packit 7cfc04
\&...
Packit 7cfc04
strfmon(convbuf, sizeof(convbuf), table[i].format, input[j]);
Packit 7cfc04
.P
Packit 7cfc04
if (j == 0) {
Packit 7cfc04
    printf("%s\t%s\t%s\en", table[i].format,
Packit 7cfc04
        convbuf, table[i].description);
Packit 7cfc04
}
Packit 7cfc04
else {
Packit 7cfc04
    printf("\t%s\en", convbuf);
Packit 7cfc04
}
Packit 7cfc04
\&...
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SS "Printing Wide Characters"
Packit 7cfc04
.P
Packit 7cfc04
The following example prints a series of wide characters. Suppose that
Packit 7cfc04
.BR \(dqL`@`\(dq 
Packit 7cfc04
expands to three bytes:
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
wchar_t wz [3] = L"@@";       // Zero-terminated
Packit 7cfc04
wchar_t wn [3] = L"@@@";      // Unterminated
Packit 7cfc04
.P
Packit 7cfc04
fprintf (stdout,"%ls", wz);   // Outputs 6 bytes
Packit 7cfc04
fprintf (stdout,"%ls", wn);   // Undefined because wn has no terminator
Packit 7cfc04
fprintf (stdout,"%4ls", wz);  // Outputs 3 bytes
Packit 7cfc04
fprintf (stdout,"%4ls", wn);  // Outputs 3 bytes; no terminator needed
Packit 7cfc04
fprintf (stdout,"%9ls", wz);  // Outputs 6 bytes
Packit 7cfc04
fprintf (stdout,"%9ls", wn);  // Outputs 9 bytes; no terminator needed
Packit 7cfc04
fprintf (stdout,"%10ls", wz); // Outputs 6 bytes
Packit 7cfc04
fprintf (stdout,"%10ls", wn); // Undefined because wn has no terminator
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.P
Packit 7cfc04
In the last line of the example, after processing three characters,
Packit 7cfc04
nine bytes have been output. The fourth character must then be examined
Packit 7cfc04
to determine whether it converts to one byte or more. If it converts
Packit 7cfc04
to more than one byte, the output is only nine bytes. Since there is
Packit 7cfc04
no fourth character in the array, the behavior is undefined.
Packit 7cfc04
.SH "APPLICATION USAGE"
Packit 7cfc04
If the application calling
Packit 7cfc04
\fIfprintf\fR()
Packit 7cfc04
has any objects of type
Packit 7cfc04
.BR wint_t
Packit 7cfc04
or
Packit 7cfc04
.BR wchar_t ,
Packit 7cfc04
it must also include the
Packit 7cfc04
.IR <wchar.h> 
Packit 7cfc04
header to have these objects defined.
Packit 7cfc04
.SH RATIONALE
Packit 7cfc04
None.
Packit 7cfc04
.SH "FUTURE DIRECTIONS"
Packit 7cfc04
None.
Packit 7cfc04
.SH "SEE ALSO"
Packit 7cfc04
.IR "Section 2.5" ", " "Standard I/O Streams",
Packit 7cfc04
.IR "\fIfputc\fR\^(\|)",
Packit 7cfc04
.IR "\fIfscanf\fR\^(\|)",
Packit 7cfc04
.IR "\fIsetlocale\fR\^(\|)",
Packit 7cfc04
.IR "\fIstrfmon\fR\^(\|)",
Packit 7cfc04
.IR "\fIwcrtomb\fR\^(\|)"
Packit 7cfc04
.P
Packit 7cfc04
The Base Definitions volume of POSIX.1\(hy2008,
Packit 7cfc04
.IR "Chapter 7" ", " "Locale",
Packit 7cfc04
.IR "\fB<stdio.h>\fP",
Packit 7cfc04
.IR "\fB<wchar.h>\fP"
Packit 7cfc04
.SH COPYRIGHT
Packit 7cfc04
Portions of this text are reprinted and reproduced in electronic form
Packit 7cfc04
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
Packit 7cfc04
-- Portable Operating System Interface (POSIX), The Open Group Base
Packit 7cfc04
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Packit 7cfc04
Electrical and Electronics Engineers, Inc and The Open Group.
Packit 7cfc04
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
Packit 7cfc04
event of any discrepancy between this version and the original IEEE and
Packit 7cfc04
The Open Group Standard, the original IEEE and The Open Group Standard
Packit 7cfc04
is the referee document. The original Standard can be obtained online at
Packit 7cfc04
http://www.unix.org/online.html .
Packit 7cfc04
Packit 7cfc04
Any typographical or formatting errors that appear
Packit 7cfc04
in this page are most likely
Packit 7cfc04
to have been introduced during the conversion of the source files to
Packit 7cfc04
man page format. To report such errors, see
Packit 7cfc04
https://www.kernel.org/doc/man-pages/reporting_bugs.html .