Split out FUNCTIONS to make this tolerable to read. Also improve readability
with lists. Describe the functions in the order of appearance in SYNOPSIS. Use CAVEATS instead of NOTES. Remove "man page spam". Etc.
This commit is contained in:
parent
a057421714
commit
e615e396bd
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: ctime.3,v 1.39 2011/04/12 08:39:26 jruoho Exp $
|
||||
.\" $NetBSD: ctime.3,v 1.40 2011/04/12 13:46:38 jruoho Exp $
|
||||
.\"
|
||||
.\" XXX: Lincense missing?
|
||||
.\"
|
||||
|
@ -29,6 +29,10 @@
|
|||
.In time.h
|
||||
.Vt extern char *tzname[2];
|
||||
.Ft char *
|
||||
.Fn asctime "const struct tm *tm"
|
||||
.Ft char *
|
||||
.Fn asctime_r "const struct tm restrict tm" "char * restrict buf"
|
||||
.Ft char *
|
||||
.Fn ctime "const time_t *clock"
|
||||
.Ft char *
|
||||
.Fn ctime_r "const time_t *clock" "char *buf"
|
||||
|
@ -36,131 +40,169 @@
|
|||
.Fn ctime_rz "const timezone_t tz" "const time_t *clock" "char *buf"
|
||||
.Ft double
|
||||
.Fn difftime "time_t time1" "time_t time0"
|
||||
.Ft char *
|
||||
.Fn asctime "const struct tm *tm"
|
||||
.Ft char *
|
||||
.Fn asctime_r "const struct tm restrict tm" "char * restrict buf"
|
||||
.Ft struct tm *
|
||||
.Fn gmtime "const time_t *clock"
|
||||
.Ft struct tm *
|
||||
.Fn gmtime_r "const time_t * restrict clock" "struct tm * restrict result"
|
||||
.Ft struct tm *
|
||||
.Fn localtime "const time_t *clock"
|
||||
.Ft struct tm *
|
||||
.Fn localtime_r "const time_t * restrict clock" "struct tm * restrict result"
|
||||
.Ft struct tm *
|
||||
.Fn localtime_rz "const timezone_t tz" "const time_t * restrict clock" "struct tm * restrict result"
|
||||
.Ft struct tm *
|
||||
.Fn gmtime "const time_t *clock"
|
||||
.Ft struct tm *
|
||||
.Fn gmtime_r "const time_t * restrict clock" "struct tm * restrict result"
|
||||
.Ft time_t
|
||||
.Fn mktime "struct tm *tm"
|
||||
.Ft time_t
|
||||
.Fn mktime_z "const timezone_t tz" "struct tm *tm"
|
||||
.Ft timezone_t
|
||||
.Fn tzalloc "const char *zone"
|
||||
.Ft const char *
|
||||
.Fn tzgetname "const timezone_t tz" "int isdst"
|
||||
.Ft void
|
||||
.Fn tzfree "const timezone_t tz"
|
||||
.Ft const char *
|
||||
.Fn tzgetname "const timezone_t tz" "int isdst"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
family of functions provide various standard library routines
|
||||
to operate with time and conversions related to time.
|
||||
.Sh FUNCTIONS
|
||||
.Bl -tag -width abcd
|
||||
.It Fn asctime "tm"
|
||||
The
|
||||
.Fn asctime
|
||||
function converts a time value contained in the
|
||||
.Fa tm
|
||||
structure to a string with the following general format:
|
||||
.Bd -literal -offset indent
|
||||
.D1 Thu Nov 24 18:22:48 1986\en\e0
|
||||
.Ed
|
||||
.Pp
|
||||
The
|
||||
.Fa tm
|
||||
structure is described in
|
||||
.Xr tm 3 .
|
||||
.It Fn asctime_r "tm" "buf"
|
||||
The
|
||||
.Fn asctime_r
|
||||
has the same behavior as
|
||||
.Fn asctime ,
|
||||
but the result is stored to
|
||||
.Fa buf ,
|
||||
which should have a size of at least 26 bytes.
|
||||
.It Fn ctime "clock"
|
||||
The
|
||||
.Fn ctime
|
||||
converts a
|
||||
function converts a
|
||||
.Vt time_t ,
|
||||
pointed to by
|
||||
.Fa clock ,
|
||||
representing the time in seconds since
|
||||
00:00:00 UTC, 1970-01-01,
|
||||
and returns a pointer to a
|
||||
string of the form
|
||||
.D1 Thu Nov 24 18:22:48 1986\en\e0
|
||||
representing the time in seconds since 00:00:00 UTC, 1970-01-01,
|
||||
and returns a pointer to a string with the format described above.
|
||||
Years requiring fewer than four characters are padded with leading zeroes.
|
||||
For years longer than four characters, the string is of the form
|
||||
.Bd -literal -offset indent
|
||||
.D1 Thu Nov 24 18:22:48 81986\en\e0
|
||||
.Ed
|
||||
.Pp
|
||||
with five spaces before the year.
|
||||
These unusual formats are designed to make it less likely that older
|
||||
software that expects exactly 26 bytes of output will mistakenly output
|
||||
misleading values for out-of-range years.
|
||||
.Pp
|
||||
.It Fn ctime_r "clock" "buf"
|
||||
The
|
||||
.Fn ctime_r
|
||||
is similar to
|
||||
.Fn ctime ,
|
||||
except it places the result of the conversion on the
|
||||
.Fa buf
|
||||
argument which should be 26 or more bytes long, instead of using a global
|
||||
static buffer.
|
||||
.Pp
|
||||
argument, which should be 26 or more bytes long,
|
||||
instead of using a global static buffer.
|
||||
.It Fn ctime_rz "tz" "clock" "buf"
|
||||
The
|
||||
.Fn ctime_rz
|
||||
is similar to
|
||||
function is similar to
|
||||
.Fn ctime_r ,
|
||||
but it also takes a
|
||||
.Ft "const timezone_t"
|
||||
argument, returned by a previous call to
|
||||
argument, as returned by a previous call to
|
||||
.Fn tzalloc .
|
||||
.Pp
|
||||
.Fn localtime
|
||||
and
|
||||
.It Fn difftime "time1" "time2"
|
||||
The
|
||||
.Fn difftime
|
||||
function returns the difference between two calendar times,
|
||||
.Fa ( time1 No - Fa time0 ) ,
|
||||
expressed in seconds.
|
||||
.It Fn gmtime "clock"
|
||||
The
|
||||
.Fn gmtime
|
||||
return pointers to
|
||||
function converts to Coordinated Universal Time
|
||||
.Pq Tn UTC
|
||||
and returns a pointer to the
|
||||
.Va tm
|
||||
structures, described below.
|
||||
structure described in
|
||||
.Xr tm 3 .
|
||||
.It Fn gmtime_r "clock" "result"
|
||||
The
|
||||
.Fn gmtime_r
|
||||
provides the same functionality as
|
||||
.Fn gmtime ,
|
||||
differing in that the caller must supply a buffer area
|
||||
.Fa result
|
||||
to which the result is stored.
|
||||
.It Fn localtime "clock"
|
||||
Also
|
||||
.Fn localtime
|
||||
is comparable to
|
||||
.Fn gmtime .
|
||||
However,
|
||||
.Fn localtime
|
||||
corrects for the time zone and any time zone adjustments
|
||||
(such as Daylight Saving Time in the U.S.A.).
|
||||
After filling in the
|
||||
.Va tm
|
||||
structure described in
|
||||
.Xr tm 3 ,
|
||||
.Fn localtime
|
||||
sets the
|
||||
structure, the function sets the
|
||||
.Fa tm_isdst Ns 'th
|
||||
element of
|
||||
.Fa tzname
|
||||
to a pointer to an
|
||||
ASCII string that's the time zone abbreviation to be used with
|
||||
ASCII string that is the time zone abbreviation to be used with
|
||||
.Fn localtime Ns 's
|
||||
return value.
|
||||
.Pp
|
||||
.Fn gmtime
|
||||
converts to Coordinated Universal Time.
|
||||
.Pp
|
||||
The
|
||||
.Fn gmtime_r
|
||||
and
|
||||
.It Fn localtime_r "clock" "result"
|
||||
As
|
||||
.Fn gmtime_r ,
|
||||
the
|
||||
.Fn localtime_r
|
||||
functions provide the same functionality as
|
||||
.Fn gmtime
|
||||
and
|
||||
.Fn localtime
|
||||
differing in that the caller must supply a buffer area
|
||||
takes an additional buffer
|
||||
.Fa result
|
||||
in which the result is stored; also,
|
||||
as a parameter and stores the result to it.
|
||||
Note however that
|
||||
.Fn localtime_r
|
||||
does not imply initialization of the local time conversion information;
|
||||
the application may need to do so by calling
|
||||
.Xr tzset 3 .
|
||||
.Pp
|
||||
.It Fn localtime_rz "tz" "clock" "result"
|
||||
The
|
||||
.Fn localtime_rz
|
||||
is similar to
|
||||
function is similar to
|
||||
.Fn localtime_r ,
|
||||
but it also takes a
|
||||
.Ft "const timezone_t"
|
||||
argument, returned by a previous call to
|
||||
.Fn tzalloc .
|
||||
.Pp
|
||||
.Fn asctime
|
||||
converts a time value contained in a
|
||||
.Dq tm
|
||||
structure to a string,
|
||||
as shown in the above example,
|
||||
and returns a pointer to the string.
|
||||
.Pp
|
||||
.It Fn mktime "tm"
|
||||
The
|
||||
.Fn mktime
|
||||
converts the broken-down time,
|
||||
expressed as local time,
|
||||
in the structure pointed to by
|
||||
.Fa tm
|
||||
into a calendar time value with the same encoding as that of the values
|
||||
returned by the
|
||||
function converts the broken-down time,
|
||||
expressed as local time in the
|
||||
.Xr tm 3
|
||||
structure, into a calendar time value with
|
||||
the same encoding as that of the values returned by the
|
||||
.Xr time 3
|
||||
function.
|
||||
The following remarks should be taken into account.
|
||||
.Bl -bullet -offset indent
|
||||
.It
|
||||
The original values of the
|
||||
.Fa tm_wday
|
||||
and
|
||||
|
@ -175,6 +217,7 @@ causes
|
|||
to presume initially that summer time (for example, Daylight Saving Time
|
||||
in the U.S.A.) respectively,
|
||||
is or is not in effect for the specified time.
|
||||
.It
|
||||
A negative value for
|
||||
.Fa tm_isdst
|
||||
causes the
|
||||
|
@ -182,7 +225,8 @@ causes the
|
|||
function to attempt to divine whether summer time is in effect
|
||||
for the specified time; in this case it does not use a consistent
|
||||
rule and may give a different answer when later
|
||||
presented with the same argument.)
|
||||
presented with the same argument.
|
||||
.It
|
||||
On successful completion, the values of the
|
||||
.Fa tm_wday
|
||||
and
|
||||
|
@ -196,33 +240,33 @@ is not set until
|
|||
and
|
||||
.Fa tm_year
|
||||
are determined.
|
||||
.Fn mktime
|
||||
returns the specified calendar time; if the calendar time cannot be
|
||||
represented, it returns
|
||||
.Va "(time_t)-1" .
|
||||
.El
|
||||
.Pp
|
||||
The function returns the specified calendar time;
|
||||
if the calendar time cannot be represented, it returns
|
||||
.Va "(time_t)-1" .
|
||||
.It Fn mktime_z "tz" "tm"
|
||||
The
|
||||
.Fn mktime_z
|
||||
is similar to
|
||||
function is similar to
|
||||
.Fn mktime
|
||||
but it also takes a
|
||||
.Ft "const timezone_t"
|
||||
argument, returned by a previous call to
|
||||
.Fn tzalloc .
|
||||
.Pp
|
||||
.Fn difftime
|
||||
returns the difference between two calendar times,
|
||||
.Fa ( time1 No - Fa time0 ) ,
|
||||
expressed in seconds.
|
||||
.Pp
|
||||
.It Fn tzalloc "zone"
|
||||
The
|
||||
.Fn tzalloc
|
||||
takes as an argument a timezone name and returns a
|
||||
function takes as an argument a timezone name and returns a
|
||||
.Ft timezone_t
|
||||
object suitable to be used in
|
||||
object suitable to be used in the
|
||||
.Fn ctime_rz ,
|
||||
.Fn localtime_rz ,
|
||||
and
|
||||
.Fn mktime_z .
|
||||
Instead of setting the environment variable
|
||||
.Fn mktime_z
|
||||
functions.
|
||||
.Pp
|
||||
Note that instead of setting the environment variable
|
||||
.Va TZ ,
|
||||
and globally changing the behavior of the calling program, one can use
|
||||
multiple timezones at the same time by using separate
|
||||
|
@ -232,7 +276,15 @@ objects allocated by
|
|||
and calling the
|
||||
.Dq z
|
||||
variants of the functions.
|
||||
.Pp
|
||||
.It Fn tzfree "tz"
|
||||
The
|
||||
.Fn tzfree
|
||||
function deallocates
|
||||
.Fa tz ,
|
||||
which was previously allocated by
|
||||
.Fn tzalloc .
|
||||
.It Fn "tzgetname"
|
||||
Finally,
|
||||
.Fn tzgetname
|
||||
returns the name for the given
|
||||
.Fa tz .
|
||||
|
@ -248,13 +300,10 @@ is set to
|
|||
.Va 1
|
||||
the call is equivalent to
|
||||
.Va tzname[1] .
|
||||
.Pp
|
||||
.Fn tzfree
|
||||
frees the
|
||||
.Fa tz
|
||||
argument previously returned by
|
||||
.Fa tzalloc .
|
||||
.El
|
||||
.Sh RETURN VALUES
|
||||
.Bl -bullet offset indent
|
||||
.It
|
||||
On success the
|
||||
.Fn asctime
|
||||
and
|
||||
|
@ -268,6 +317,7 @@ function return a pointer to the user-supplied buffer.
|
|||
On failure they all return
|
||||
.Dv NULL
|
||||
and no errors are defined for them.
|
||||
.It
|
||||
On success the
|
||||
.Fn gmtime ,
|
||||
and
|
||||
|
@ -286,6 +336,7 @@ On failure they all return
|
|||
and the global variable
|
||||
.Va errno
|
||||
is set to indicate the error.
|
||||
.It
|
||||
The
|
||||
.Fn mktime
|
||||
and
|
||||
|
@ -302,6 +353,7 @@ return
|
|||
setting the global variable
|
||||
.Va errno
|
||||
to indicate the error.
|
||||
.It
|
||||
The
|
||||
.Fn tzalloc
|
||||
function returns a pointer to a
|
||||
|
@ -311,9 +363,11 @@ object or
|
|||
on failure, setting
|
||||
.Va errno
|
||||
to indicate the error.
|
||||
.It
|
||||
.Fn tzgetzone
|
||||
function returns string containing the name of the timezone given in
|
||||
.Fa tz .
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width /usr/share/zoneinfo/posixrules -compact
|
||||
.It Pa /etc/localtime
|
||||
|
@ -331,17 +385,7 @@ If
|
|||
is absent, UTC leap seconds are loaded from
|
||||
.Pa /usr/share/zoneinfo/posixrules .
|
||||
.Sh ERRORS
|
||||
The
|
||||
.Fn gmtime_r ,
|
||||
.Fn localtime_r ,
|
||||
.Fn localtime_rz ,
|
||||
.Fn gmtime ,
|
||||
.Fn localtime ,
|
||||
and
|
||||
.Fn mktime ,
|
||||
and
|
||||
.Fn mktime_z
|
||||
will fail when:
|
||||
The described functions may fail with
|
||||
.Bl -tag -width Er
|
||||
.It Bq Er EINVAL
|
||||
The result cannot be represented.
|
||||
|
@ -349,7 +393,7 @@ The result cannot be represented.
|
|||
The result cannot be represented.
|
||||
.El
|
||||
.Pp
|
||||
All functions that return values except their
|
||||
All functions that return values, except their
|
||||
.Dq z
|
||||
variants, can also return the same errors as
|
||||
.Xr open 2
|
||||
|
@ -372,16 +416,10 @@ The
|
|||
and
|
||||
.Fn mktime
|
||||
functions conform to
|
||||
.St -ansiC
|
||||
The
|
||||
.Fn ctime_r ,
|
||||
.Fn asctime_r ,
|
||||
.Fn localtime_r
|
||||
and
|
||||
.Fn gmtime_r
|
||||
functions conform to
|
||||
.St -p1003.1c-95 .
|
||||
.Sh NOTES
|
||||
.St -ansiC .
|
||||
Rest of the functions conform to
|
||||
.St -p1003.1-2008 .
|
||||
.Sh CAVEATS
|
||||
The return values point to static data; the data is overwritten by
|
||||
each call.
|
||||
The
|
||||
|
@ -393,10 +431,11 @@ will also be overwritten at the next call
|
|||
(and by calls to
|
||||
.Xr tzset 3 ) .
|
||||
.Pp
|
||||
The
|
||||
.Fn asctime
|
||||
and
|
||||
.Fn ctime
|
||||
behave strangely for years before 1000 or after 9999.
|
||||
functions behave strangely for years before 1000 or after 9999.
|
||||
The 1989 and 1999 editions of the C Standard say
|
||||
that years from \-99 through 999 are converted without
|
||||
extra spaces, but this conflicts with longstanding
|
||||
|
|
Loading…
Reference in New Issue