Tue Apr 12 08:39:26 2011 UTC ()
Move some of the discussion from the messy ctime(3) to tm(3).


(jruoho)
diff -r1.38 -r1.39 src/lib/libc/time/ctime.3
diff -r1.11 -r1.12 src/share/man/man3/timeval.3
diff -r1.1 -r1.2 src/share/man/man3/tm.3

cvs diff -r1.38 -r1.39 src/lib/libc/time/ctime.3 (expand / switch to unified diff)

--- src/lib/libc/time/ctime.3 2011/01/24 19:37:35 1.38
+++ src/lib/libc/time/ctime.3 2011/04/12 08:39:26 1.39
@@ -1,15 +1,18 @@ @@ -1,15 +1,18 @@
1.\" $NetBSD: ctime.3,v 1.38 2011/01/24 19:37:35 njoly Exp $ 1.\" $NetBSD: ctime.3,v 1.39 2011/04/12 08:39:26 jruoho Exp $
2.Dd December 14, 2010 2.\"
 3.\" XXX: Lincense missing?
 4.\"
 5.Dd April 12, 2011
3.Dt CTIME 3 6.Dt CTIME 3
4.Os 7.Os
5.Sh NAME 8.Sh NAME
6.Nm asctime , 9.Nm asctime ,
7.Nm asctime_r , 10.Nm asctime_r ,
8.Nm ctime , 11.Nm ctime ,
9.Nm ctime_r , 12.Nm ctime_r ,
10.Nm ctime_rz , 13.Nm ctime_rz ,
11.Nm difftime , 14.Nm difftime ,
12.Nm gmtime , 15.Nm gmtime ,
13.Nm gmtime_r , 16.Nm gmtime_r ,
14.Nm localtime , 17.Nm localtime ,
15.Nm localtime_r , 18.Nm localtime_r ,
@@ -93,27 +96,28 @@ argument, returned by a previous call to @@ -93,27 +96,28 @@ argument, returned by a previous call to
93.Fn tzalloc . 96.Fn tzalloc .
94.Pp 97.Pp
95.Fn localtime 98.Fn localtime
96and 99and
97.Fn gmtime 100.Fn gmtime
98return pointers to 101return pointers to
99.Va tm 102.Va tm
100structures, described below. 103structures, described below.
101.Fn localtime 104.Fn localtime
102corrects for the time zone and any time zone adjustments 105corrects for the time zone and any time zone adjustments
103(such as Daylight Saving Time in the U.S.A.). 106(such as Daylight Saving Time in the U.S.A.).
104After filling in the 107After filling in the
105.Va tm 108.Va tm
106structure, 109structure described in
 110.Xr tm 3 ,
107.Fn localtime 111.Fn localtime
108sets the 112sets the
109.Fa tm_isdst Ns 'th 113.Fa tm_isdst Ns 'th
110element of 114element of
111.Fa tzname 115.Fa tzname
112to a pointer to an 116to a pointer to an
113ASCII string that's the time zone abbreviation to be used with 117ASCII string that's the time zone abbreviation to be used with
114.Fn localtime Ns 's 118.Fn localtime Ns 's
115return value. 119return value.
116.Pp 120.Pp
117.Fn gmtime 121.Fn gmtime
118converts to Coordinated Universal Time. 122converts to Coordinated Universal Time.
119.Pp 123.Pp
@@ -240,72 +244,26 @@ the call is equivalent to @@ -240,72 +244,26 @@ the call is equivalent to
240.Va tzname[0] . 244.Va tzname[0] .
241If 245If
242.Fa isdst 246.Fa isdst
243is set to 247is set to
244.Va 1 248.Va 1
245the call is equivalent to 249the call is equivalent to
246.Va tzname[1] . 250.Va tzname[1] .
247.Pp 251.Pp
248.Fn tzfree 252.Fn tzfree
249frees the 253frees the
250.Fa tz 254.Fa tz
251argument previously returned by 255argument previously returned by
252.Fa tzalloc . 256.Fa tzalloc .
253.Pp 
254The structure (of type) 
255.Va "struct tm" 
256includes the following fields: 
257.Bd -literal -offset indent 
258int tm_sec; /* seconds after the minute [0,61] */ 
259int tm_min; /* minutes after the hour [0,59] */ 
260int tm_hour; /* hours since midnight [0,23] */ 
261int tm_mday; /* day of the month [1,31] */ 
262int tm_mon; /* months since January [0,11] */ 
263int tm_year; /* years since 1900 */ 
264int tm_wday; /* day of week [0,6] (Sunday = 0) */ 
265int tm_yday; /* day of year [0,365] (Jan 1 = 0) */ 
266int tm_isdst; /* daylight savings flag */ 
267long tm_gmtoff; /* offset from UTC in seconds */ 
268char *tm_zone; /* abbreviation of timezone name */ 
269.Ed 
270.Pp 
271The 
272.Fa tm_zone 
273and 
274.Fa tm_gmtoff 
275fields exist, and are filled in, only if arrangements to do 
276so were made when the library containing these functions was 
277created. 
278There is no guarantee that these fields will continue to exist 
279in this form in future releases of this code. 
280The 
281.Fa tm_zone 
282field will become invalid and point to freed storage if the corresponding 
283.Va "struct tm" 
284was returned by 
285.Fn localtime_rz 
286and the 
287.Ft "const timezone_t" 
288.Fa tz 
289argument has been freed by 
290.Fn tzfree . 
291.Pp 
292.Fa tm_isdst 
293is non-zero if summer time is in effect. 
294.Pp 
295.Fa tm_gmtoff 
296is the offset (in seconds) of the time represented 
297from UTC, with positive values indicating east 
298of the Prime Meridian. 
299.Sh RETURN VALUES 257.Sh RETURN VALUES
300On success the 258On success the
301.Fn asctime 259.Fn asctime
302and 260and
303.Fn ctime 261.Fn ctime
304functions return a pointer to a static character buffer, and the 262functions return a pointer to a static character buffer, and the
305.Fn asctime_r , 263.Fn asctime_r ,
306.Fn ctime_r , 264.Fn ctime_r ,
307and 265and
308.Fn ctime_rz 266.Fn ctime_rz
309function return a pointer to the user-supplied buffer. 267function return a pointer to the user-supplied buffer.
310On failure they all return 268On failure they all return
311.Dv NULL 269.Dv NULL
@@ -391,26 +349,27 @@ The result cannot be represented. @@ -391,26 +349,27 @@ The result cannot be represented.
391The result cannot be represented. 349The result cannot be represented.
392.El 350.El
393.Pp 351.Pp
394All functions that return values except their 352All functions that return values except their
395.Dq z 353.Dq z
396variants, can also return the same errors as 354variants, can also return the same errors as
397.Xr open 2 355.Xr open 2
398and 356and
399.Xr malloc 3 . 357.Xr malloc 3 .
400.Sh SEE ALSO 358.Sh SEE ALSO
401.Xr getenv 3 , 359.Xr getenv 3 ,
402.Xr strftime 3 , 360.Xr strftime 3 ,
403.Xr time 3 , 361.Xr time 3 ,
 362.Xr tm 3 ,
404.Xr tzset 3 , 363.Xr tzset 3 ,
405.Xr tzfile 5 364.Xr tzfile 5
406.Sh STANDARDS 365.Sh STANDARDS
407The 366The
408.Fn ctime , 367.Fn ctime ,
409.Fn difftime , 368.Fn difftime ,
410.Fn asctime , 369.Fn asctime ,
411.Fn localtime , 370.Fn localtime ,
412.Fn gmtime 371.Fn gmtime
413and 372and
414.Fn mktime 373.Fn mktime
415functions conform to 374functions conform to
416.St -ansiC 375.St -ansiC

cvs diff -r1.11 -r1.12 src/share/man/man3/timeval.3 (expand / switch to unified diff)

--- src/share/man/man3/timeval.3 2010/06/08 05:50:01 1.11
+++ src/share/man/man3/timeval.3 2011/04/12 08:39:26 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: timeval.3,v 1.11 2010/06/08 05:50:01 jruoho Exp $ 1.\" $NetBSD: timeval.3,v 1.12 2011/04/12 08:39:26 jruoho Exp $
2.\" 2.\"
3.\" Copyright (c) 2010 The NetBSD Foundation, Inc. 3.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation 6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jukka Ruohonen. 7.\" by Jukka Ruohonen.
8.\" 8.\"
9.\" Redistribution and use in source and binary forms, with or without 9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions 10.\" modification, are permitted provided that the following conditions
11.\" are met: 11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright 12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer. 13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" 2. Redistributions in binary form must reproduce the above copyright
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17.\" 17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE. 28.\" POSSIBILITY OF SUCH DAMAGE.
29.\" 29.\"
30.Dd June 8, 2010 30.Dd April 12, 2011
31.Dt TIMEVAL 3 31.Dt TIMEVAL 3
32.Os 32.Os
33.Sh NAME 33.Sh NAME
34.Nm timeval , 34.Nm timeval ,
35.Nm timespec , 35.Nm timespec ,
36.Nm itimerval , 36.Nm itimerval ,
37.Nm itimerspec , 37.Nm itimerspec ,
38.Nm bintime 38.Nm bintime
39.Nd time structures 39.Nd time structures
40.Sh SYNOPSIS 40.Sh SYNOPSIS
41.In sys/time.h 41.In sys/time.h
42.Ft void 42.Ft void
43.Fn TIMEVAL_TO_TIMESPEC "struct timeval *tv" "struct timespec *ts" 43.Fn TIMEVAL_TO_TIMESPEC "struct timeval *tv" "struct timespec *ts"
@@ -175,14 +175,15 @@ example(struct timespec *spec, time_t mi @@ -175,14 +175,15 @@ example(struct timespec *spec, time_t mi
175 175
176 _DIAGASSERT(spec != NULL); 176 _DIAGASSERT(spec != NULL);
177 TIMEVAL_TO_TIMESPEC(&elapsed, spec); 177 TIMEVAL_TO_TIMESPEC(&elapsed, spec);
178 178
179 /* Add the offset for timeout in minutes. */ 179 /* Add the offset for timeout in minutes. */
180 spec->tv_sec = spec->tv_sec + minutes * 60; 180 spec->tv_sec = spec->tv_sec + minutes * 60;
181} 181}
182.Ed 182.Ed
183.Pp 183.Pp
184A better alternative would use the more precise 184A better alternative would use the more precise
185.Xr clock_gettime 2 . 185.Xr clock_gettime 2 .
186.Sh SEE ALSO 186.Sh SEE ALSO
187.Xr timeradd 3 , 187.Xr timeradd 3 ,
 188.Xr tm 3 ,
188.Xr bintime_add 9 189.Xr bintime_add 9

cvs diff -r1.1 -r1.2 src/share/man/man3/tm.3 (expand / switch to unified diff)

--- src/share/man/man3/tm.3 2011/04/12 08:22:49 1.1
+++ src/share/man/man3/tm.3 2011/04/12 08:39:26 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: tm.3,v 1.1 2011/04/12 08:22:49 jruoho Exp $ 1.\" $NetBSD: tm.3,v 1.2 2011/04/12 08:39:26 jruoho Exp $
2.\" 2.\"
3.\" Copyright (c) 2011 Jukka Ruohonen <jruohonen@iki.fi> 3.\" Copyright (c) 2011 Jukka Ruohonen <jruohonen@iki.fi>
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
8.\" are met: 8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright 9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer. 10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 14.\"
@@ -72,20 +72,48 @@ The members are: @@ -72,20 +72,48 @@ The members are:
72The 72The
73.Vt tm 73.Vt tm
74structure is used by various common library routines such as 74structure is used by various common library routines such as
75.Xr mktime 3 , 75.Xr mktime 3 ,
76.Xr localtime 3 , 76.Xr localtime 3 ,
77and 77and
78.Xr strptime 3 . 78.Xr strptime 3 .
79All except 79All except
80.Va tm_gmtoff 80.Va tm_gmtoff
81and 81and
82.Va tm_zone 82.Va tm_zone
83are defined in 83are defined in
84.St -p1003.1-2008 . 84.St -p1003.1-2008 .
 85.Ss NetBSD Extensions
 86The
 87.Va tm_zone
 88and
 89.Va tm_gmtoff
 90fields exist, and are filled in by applicable library routines,
 91only if arrangements to do so were made when the library containing
 92these functions was created.
 93There is no guarantee that these fields will continue to exist
 94in this form in future releases of
 95. Nx .
 96.Pp
 97The
 98.Fa tm_gmtoff
 99field denotes the offset (in seconds) of the time represented
 100from UTC, with positive values indicating east
 101of the Prime Meridian.
 102The
 103.Vt tm_zone
 104field will become invalid and point to freed storage if the corresponding
 105.Va "struct tm"
 106was returned by
 107.Xr localtime_rz 3
 108and the
 109.Ft "const timezone_t"
 110.Fa tz
 111argument has been freed by
 112.Xr tzfree 3 .
85.Sh SEE ALSO 113.Sh SEE ALSO
86.Xr timeval 3 114.Xr timeval 3
87.Sh STANDARDS 115.Sh STANDARDS
88The 116The
89.Vt tm 117.Vt tm
90structure conforms to 118structure conforms to
91.St -p1003.1-2008 . 119.St -p1003.1-2008 .