xref: /freebsd/lib/libc/gen/time.3 (revision ee12faa062c04a49bf6fe4e6867bad8606e2413f)
1.\" Copyright (c) 1989, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the American National Standards Committee X3, on Information
6.\" Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)time.3	8.1 (Berkeley) 6/4/93
33.\"
34.Dd April 14, 2022
35.Dt TIME 3
36.Os
37.Sh NAME
38.Nm time
39.Nd get time of day
40.Sh LIBRARY
41.Lb libc
42.Sh SYNOPSIS
43.In time.h
44.Ft time_t
45.Fn time "time_t *tloc"
46.Sh DESCRIPTION
47The
48.Fn time
49function
50returns the value of time in seconds since 0 hours, 0 minutes,
510 seconds, January 1, 1970, Coordinated Universal Time (UTC).
52If an error occurs,
53.Fn time
54returns the value
55.Po Vt time_t Pc Ns \-1 .
56.Pp
57The return value is also stored in
58.No \&* Ns Va tloc ,
59provided that
60.Va tloc
61is non-null.
62.Sh ERRORS
63The
64.Fn time
65function may fail for any of the reasons described in
66.Xr clock_gettime 2 .
67.Sh SEE ALSO
68.Xr clock_gettime 2 ,
69.Xr gettimeofday 2 ,
70.Xr ctime 3
71.Sh STANDARDS
72The
73.Nm
74function conforms to
75.St -p1003.1-2008 .
76.Sh HISTORY
77The
78.Fn time
79system call first appeared in
80.At v1 .
81Through the
82.At v3 ,
83it returned 60 Hz ticks since an epoch that changed occasionally, because it
84was a 32-bit value that overflowed in a little over 2 years.
85.Pp
86In
87.At v4
88the granularity of the return value was reduced to whole seconds,
89delaying the aforementioned overflow until 2038.
90.Pp
91.At v7
92introduced the
93.Fn ftime
94system call, which returned time at a millisecond level,
95though retained the
96.Fn gtime
97system call (exposed as
98.Fn time
99in userland).
100.Fn time
101could have been implemented as a wrapper around
102.Fn ftime ,
103but that wasn't done.
104.Pp
105.Bx 4.1c
106implemented a higher-precision time function
107.Fn gettimeofday
108to replace
109.Fn ftime
110and reimplemented
111.Fn time
112in terms of that.
113.Pp
114Since
115.Fx 9
116the implementation of
117.Fn time
118uses
119.Fn clock_gettime "CLOCK_SECOND"
120instead of
121.Fn gettimeofday
122for performance reasons.
123.Sh BUGS
124Neither
125.St -isoC-99
126nor
127.St -p1003.1-2001
128requires
129.Fn time
130to set
131.Va errno
132on failure; thus, it is impossible for an application to distinguish
133the valid time value \-1 (representing the last UTC second of 1969)
134from the error return value.
135.Pp
136Systems conforming to earlier versions of the C and POSIX
137standards (including older versions of
138.Fx )
139did not set
140.No \&* Ns Va tloc
141in the error case.
142