xref: /freebsd/lib/libc/gen/time.3 (revision 2e3f49888ec8851bafb22011533217487764fdb0)
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.Dd April 14, 2022
33.Dt TIME 3
34.Os
35.Sh NAME
36.Nm time
37.Nd get time of day
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In time.h
42.Ft time_t
43.Fn time "time_t *tloc"
44.Sh DESCRIPTION
45The
46.Fn time
47function
48returns the value of time in seconds since 0 hours, 0 minutes,
490 seconds, January 1, 1970, Coordinated Universal Time (UTC).
50If an error occurs,
51.Fn time
52returns the value
53.Po Vt time_t Pc Ns \-1 .
54.Pp
55The return value is also stored in
56.No \&* Ns Va tloc ,
57provided that
58.Va tloc
59is non-null.
60.Sh ERRORS
61The
62.Fn time
63function may fail for any of the reasons described in
64.Xr clock_gettime 2 .
65.Sh SEE ALSO
66.Xr clock_gettime 2 ,
67.Xr gettimeofday 2 ,
68.Xr ctime 3
69.Sh STANDARDS
70The
71.Nm
72function conforms to
73.St -p1003.1-2008 .
74.Sh HISTORY
75The
76.Fn time
77system call first appeared in
78.At v1 .
79Through the
80.At v3 ,
81it returned 60 Hz ticks since an epoch that changed occasionally, because it
82was a 32-bit value that overflowed in a little over 2 years.
83.Pp
84In
85.At v4
86the granularity of the return value was reduced to whole seconds,
87delaying the aforementioned overflow until 2038.
88.Pp
89.At v7
90introduced the
91.Fn ftime
92system call, which returned time at a millisecond level,
93though retained the
94.Fn gtime
95system call (exposed as
96.Fn time
97in userland).
98.Fn time
99could have been implemented as a wrapper around
100.Fn ftime ,
101but that wasn't done.
102.Pp
103.Bx 4.1c
104implemented a higher-precision time function
105.Fn gettimeofday
106to replace
107.Fn ftime
108and reimplemented
109.Fn time
110in terms of that.
111.Pp
112Since
113.Fx 9
114the implementation of
115.Fn time
116uses
117.Fn clock_gettime "CLOCK_SECOND"
118instead of
119.Fn gettimeofday
120for performance reasons.
121.Sh BUGS
122Neither
123.St -isoC-99
124nor
125.St -p1003.1-2001
126requires
127.Fn time
128to set
129.Va errno
130on failure; thus, it is impossible for an application to distinguish
131the valid time value \-1 (representing the last UTC second of 1969)
132from the error return value.
133.Pp
134Systems conforming to earlier versions of the C and POSIX
135standards (including older versions of
136.Fx )
137did not set
138.No \&* Ns Va tloc
139in the error case.
140