This commit is contained in:
Michael Kerrisk 2007-07-09 21:02:59 +00:00
parent d089e7b597
commit 5adafd6d79
5 changed files with 131 additions and 52 deletions

View File

@ -69,12 +69,20 @@ C99, POSIX.1-2001.
.SH NOTES
Wide-character output to a byte oriented stream can be performed through the
.BR fprintf (3)
function with the %lc and %ls directives.
function with the
.B %lc
and
.B %ls
directives.
.PP
Char oriented output to a wide-character oriented stream can be performed
through the
.BR fwprintf (3)
function with the %c and %s directives.
function with the
.B %c
and
.B %s
directives.
.SH "SEE ALSO"
.BR fprintf (3),
.BR fwprintf (3)

View File

@ -226,7 +226,7 @@ An optional
For example, the
.B l
type modifier is used with integer conversions such as
.I %d
.B %d
to specify that the corresponding
.I pointer
argument refers to a
@ -248,9 +248,9 @@ The two forms should not be mixed in the same
string, except that a string containing
"\fB%\fP\fIn\fP\fB$\fP"
specifications can include
.I %%
.B %%
and
.IR %* .
.BR %* .
If
.I format
contains '%'
@ -323,9 +323,9 @@ Specifying two
characters is equivalent to
.BR L .
If used with
.I %c
.B %c
or
.I %s
.B %s
the corresponding parameter is considered
as a pointer to a wide character or wide-character string respectively.
.\" This use of l was introduced in Amendment 1 to ISO C90.
@ -372,7 +372,7 @@ are available:
.B %
Matches a literal '%'.
That is,
.I %\&%
.B %\&%
in the format string matches a
single input '%' character.
No conversion is done, and assignment does not
@ -389,7 +389,7 @@ Equivalent to
this exists only for backwards compatibility.
(Note: thus only in libc4.
In libc5 and glibc the
.I %D
.B %D
is silently ignored, causing old programs to fail mysteriously.)
.TP
.B i
@ -497,7 +497,7 @@ circumflex, in) set or when the field width runs out.
.TP
.B p
Matches a pointer value (as printed by
.I %p
.B %p
in
.BR printf (3);
the next pointer must be a pointer to a pointer to
@ -514,13 +514,13 @@ a conversion, although it can be suppressed with the
.B *
assignment-suppression character.
The C standard says: "Execution of a
.I %n
.B %n
directive does not increment
the assignment count returned at the completion of execution"
but the Corrigendum seems to contradict this.
Probably it is wise
not to make any assumptions on the effect of
.I %n
.B %n
conversions on the return value.
.SH "RETURN VALUE"
These functions return the number of input items

View File

@ -79,34 +79,48 @@ The century number (year/100) as a 2-digit integer. (SU)
The day of the month as a decimal number (range 01 to 31).
.TP
.B %D
Equivalent to %m/%d/%y. (Yecch \(em for Americans only.
Americans should note that in other countries %d/%m/%y is rather
common.
Equivalent to
.BR %m/%d/%y .
(Yecch \(em for Americans only.
Americans should note that in other countries
.BR %d/%m/%y
is rather common.
This means that in international context this format is
ambiguous and should not be used.) (SU)
.TP
.B %e
Like %d, the day of the month as a decimal number, but a leading
Like
.BR %d ,
the day of the month as a decimal number, but a leading
zero is replaced by a space. (SU)
.TP
.B %E
Modifier: use alternative format, see below. (SU)
.TP
.B %F
Equivalent to %Y-%m-%d (the ISO 8601 date format). (C99)
Equivalent to
.B %Y-%m-%d
(the ISO 8601 date format). (C99)
.TP
.B %G
The ISO 8601 year with century as a decimal number.
The 4-digit year corresponding to the ISO week number (see %V).
This has the same format and value as %y, except that if the
The 4-digit year corresponding to the ISO week number (see
.BR %V ).
This has the same format and value as
.BR %y ,
except that if the
ISO week number belongs to the previous or next year,
that year is used instead. (TZ)
.TP
.B %g
Like %G, but without century, that is, with a 2-digit year (00-99). (TZ)
Like
.BR %G ,
but without century, that is, with a 2-digit year (00-99). (TZ)
.TP
.B %h
Equivalent to %b. (SU)
Equivalent to
.BR %b .
(SU)
.TP
.B %H
The hour as a decimal number using a 24-hour clock (range 00 to 23).
@ -119,11 +133,15 @@ The day of the year as a decimal number (range 001 to 366).
.TP
.B %k
The hour (24-hour clock) as a decimal number (range 0 to 23);
single digits are preceded by a blank. (See also %H.) (TZ)
single digits are preceded by a blank. (See also
.BR %H .)
(TZ)
.TP
.B %l
The hour (12-hour clock) as a decimal number (range 1 to 12);
single digits are preceded by a blank. (See also %I.) (TZ)
single digits are preceded by a blank. (See also
.BR %I .)
(TZ)
.TP
.B %m
The month as a decimal number (range 01 to 12).
@ -143,16 +161,22 @@ corresponding strings for the current locale.
Noon is treated as `pm' and midnight as `am'.
.TP
.B %P
Like %p but in lowercase: `am' or `pm' or a corresponding
Like
.B %p
but in lowercase: `am' or `pm' or a corresponding
string for the current locale. (GNU)
.TP
.B %r
The time in a.m. or p.m. notation.
In the POSIX locale this is equivalent to `%I:%M:%S %p'. (SU)
In the POSIX locale this is equivalent to
.BR %I:%M:%S %p .
(SU)
.TP
.B %R
The time in 24-hour notation (%H:%M). (SU)
For a version including the seconds, see %T below.
The time in 24-hour notation (\fB%H:%M\fP). (SU)
For a version including the seconds, see
.B %T
below.
.TP
.B %s
The number of seconds since the Epoch, that is, since 1970-01-01
@ -166,28 +190,38 @@ The second as a decimal number (range 00 to 60).
A tab character. (SU)
.TP
.B %T
The time in 24-hour notation (%H:%M:%S). (SU)
The time in 24-hour notation (\fB%H:%M:%S\fP). (SU)
.TP
.B %u
The day of the week as a decimal, range 1 to 7, Monday being 1.
See also %w. (SU)
See also
.BR %w .
(SU)
.TP
.B %U
The week number of the current year as a decimal number,
range 00 to 53, starting with the first Sunday as the first day
of week 01.
See also %V and %W.
See also
.B %V
and
.BR %W .
.TP
.B %V
The ISO 8601:1988 week number of the current year as a decimal number,
range 01 to 53, where week 1 is the first week that has at least
4 days in the current year, and with Monday as the first day of
the week.
See also %U and %W. (SU)
See also
.B %U
and
.BR %W .
(SU)
.TP
.B %w
The day of the week as a decimal, range 0 to 6, Sunday being 0.
See also %u.
See also
.BR %u .
.TP
.B %W
The week number of the current year as a decimal number,
@ -252,7 +286,9 @@ very old versions of libc, such as libc 4.4.1,
would return \fImax\fP if the array was too small.)
.LP
Note that the return value 0 does not necessarily indicate an error;
for example, in many locales %p yields an empty string.
for example, in many locales
.B %p
yields an empty string.
.SH ENVIRONMENT
The environment variables TZ and
.B LC_TIME
@ -262,17 +298,22 @@ SVr4, C89, C99.
There are strict inclusions between the set of conversions
given in ANSI C (unmarked), those given in the Single Unix Specification
(marked SU), those given in Olson's timezone package (marked TZ),
and those given in glibc (marked GNU), except that %+ is not supported
in glibc2.
and those given in glibc (marked GNU), except that
.B %+
is not supported in glibc2.
On the other hand glibc2 has several more extensions.
POSIX.1 only refers to ANSI C; POSIX.2 describes under
.BR date (1)
several extensions that could apply to
.BR strftime ()
as well.
The %F conversion is in C99 and POSIX.1-2001.
The
.B %F
conversion is in C99 and POSIX.1-2001.
In SUSv2, the %S specifier allowed a range of 00 to 61,
In SUSv2, the
.B %S
specifier allowed a range of 00 to 61,
to allow for the theoretical possibility of a minute that
included a double leap second
(there never has been such a minute).
@ -310,18 +351,25 @@ Convert alphabetic characters in result string to upper case.
.B #
Swap the case of the result string.
(This flag only works with certain conversion specifier characters,
and of these, it is only really useful with %Z).
and of these, it is only really useful with
.BR %Z ).
.PP
An optional decimal width specifier may follow the (possibly absent) flag.
If the natural size of the field is smaller than this width,
then the result string is padded (on the left) to the specified width.
.SH BUGS
Some buggy versions of gcc complain about the use of %c:
Some buggy versions of
.BR gcc (1)
complain about the use of
.BR %c :
.IR "warning: `%c' yields only last 2 digits of year in some locales" .
Of course programmers are encouraged to use %c, it gives the preferred
Of course programmers are encouraged to use
.BR %c , it gives the preferred
date and time representation.
One meets all kinds of strange obfuscations
to circumvent this gcc problem.
to circumvent this
.BR gcc (1)
problem.
A relatively clean one is to add an
intermediate function
.in +0.5i

View File

@ -104,10 +104,14 @@ The century number (0-99).
The day of month (1-31).
.TP
.B %D
Equivalent to %m/%d/%y.
Equivalent to
.BR %m/%d/%y .
(This is the American style date, very confusing
to non-Americans, especially since %d/%m/%y is widely used in Europe.
The ISO 8601 standard format is %Y-%m-%d.)
to non-Americans, especially since
.B %d/%m/%y
is widely used in Europe.
The ISO 8601 standard format is
.BR %Y-%m-%d .)
.TP
.BR %H
The hour (0-23).
@ -132,14 +136,16 @@ The locale's equivalent of AM or PM. (Note: there may be none.)
.TP
.B %r
The 12-hour clock time (using the locale's AM or PM).
In the POSIX locale equivalent to %I:%M:%S %p.
In the POSIX locale equivalent to
.BR "%I:%M:%S %p" .
If \fIt_fmt_ampm\fP is empty in the
.B LC_TIME
part of the current locale
then the behavior is undefined.
.TP
.B %R
Equivalent to %H:%M.
Equivalent to
.BR %H:%M .
.TP
.B %S
The second (0-60; 60 may occur for leap seconds;
@ -149,7 +155,8 @@ earlier also 61 was allowed).
Arbitrary whitespace.
.TP
.B %T
Equivalent to %H:%M:%S.
Equivalent to
.BR %H:%M:%S .
.TP
.B %U
The week number with Sunday the first day of the week (0-53).
@ -199,7 +206,9 @@ The locale's alternative date representation.
The locale's alternative time representation.
.TP
.B %Ey
The offset from %EC (year only) in the locale's alternative representation.
The offset from
.B %EC
(year only) in the locale's alternative representation.
.TP
.B %EY
The full alternative year representation.
@ -239,7 +248,9 @@ The week number of the year (Monday as the first day of the week)
using the locale's alternative numeric symbols.
.TP
.B %Oy
The year (offset from %C) using the locale's alternative numeric symbols.
The year (offset from
.BR %C )
using the locale's alternative numeric symbols.
.LP
The broken-down time structure \fItm\fP is defined in \fI<time.h>\fP
as follows:
@ -345,8 +356,18 @@ The timezone name.
.LP
Similarly, because of GNU extensions to
.BR strftime (3),
%k is accepted as a synonym for %H, and %l should be accepted
as a synonym for %I, and %P is accepted as a synonym for %p.
.B %k
is accepted as a synonym for
.BR %H ,
and
.B %l
should be accepted
as a synonym for
.BR %I ,
and
.B %P
is accepted as a synonym for
.BR %p .
Finally
.TP
.B %s

View File

@ -107,7 +107,9 @@ as in
.BR printf (3)
and any arguments required by the
.IR format ,
except that the two character sequence %m will be replaced by
except that the two character sequence
.B %m
will be replaced by
the error message string
.IR strerror ( errno ).
A trailing newline may be added if needed.