1.\"	$MirOS: src/lib/libc/sys/gettimeofday.2,v 1.3 2005/09/22 20:17:49 tg Exp $
2.\"	$OpenBSD: gettimeofday.2,v 1.15 2005/05/19 08:15:25 jmc Exp $
3.\"
4.\" Copyright (c) 1980, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)gettimeofday.2	8.2 (Berkeley) 5/26/95
32.\"
33.Dd May 26, 1995
34.Dt GETTIMEOFDAY 2
35.Os
36.Sh NAME
37.Nm gettimeofday ,
38.Nm settimeofday
39.Nd get/set date and time
40.Sh SYNOPSIS
41.Fd #include <sys/time.h>
42.Ft int
43.Fn gettimeofday "struct timeval *tp" "struct timezone *tzp"
44.Ft int
45.Fn settimeofday "const struct timeval *tp" "const struct timezone *tzp"
46.Sh DESCRIPTION
47.Bf -symbolic
48Note: timezone is no longer used; this information is kept outside
49the kernel.
50.Ef
51.Pp
52The system's notion of the current Greenwich time and the current time
53zone is obtained with the
54.Fn gettimeofday
55call, and set with the
56.Fn settimeofday
57call.
58The time is expressed in seconds and microseconds since the epoch,
5900:00:00 seconds at midnight (0 hour), January 1, 1970, Temps
60Atomique International (TAI).
61Leap seconds are counted, violating POSIX but providing correct time.
62The resolution of the system clock is hardware dependent, and the time
63may be updated continuously or in
64.Dq ticks .
65If
66.Fa tp
67or
68.Fa tzp
69is
70.Dv NULL ,
71the associated time
72information will not be returned or set.
73.Pp
74The structures pointed to by
75.Fa tp
76and
77.Fa tzp
78are defined in
79.Aq Pa sys/time.h
80as:
81.Bd -literal
82struct timeval {
83	time_t	tv_sec;		/* seconds since Jan. 1, 1970, 00:00:00 */
84	long	tv_usec;	/* and microseconds */
85};
86
87struct timezone {
88	int	tz_minuteswest; /* of Greenwich */
89	int	tz_dsttime;	/* type of dst correction to apply */
90};
91.Ed
92.Pp
93The
94.Fa timezone
95structure indicates the local time zone
96(measured in minutes of time westward from Greenwich),
97and a flag that, if nonzero, indicates that
98Daylight Saving time applies locally during
99the appropriate part of the year.
100.Pp
101Only the superuser may set the time of day or time zone.
102If the system securelevel is greater than 1 (see
103.Xr init 8 ) ,
104the time may only be advanced.
105This limitation is imposed to prevent a malicious superuser
106from setting arbitrary time stamps on files.
107The system time can still be adjusted backwards using the
108.Xr adjtime 2
109system call even when the system is secure.
110.Sh RETURN VALUES
111A 0 return value indicates that the call succeeded.
112A \-1 return value indicates an error occurred, and in this
113case an error code is stored into the global variable
114.Va errno .
115.Sh ERRORS
116The following error codes may be set in
117.Va errno :
118.Bl -tag -width [EFAULT]
119.It Bq Er EFAULT
120An argument address referenced invalid memory.
121.It Bq Er EPERM
122A user other than the superuser attempted to set the time.
123.El
124.Sh SEE ALSO
125.Xr date 1 ,
126.Xr adjtime 2 ,
127.Xr getitimer 2 ,
128.Xr ctime 3 ,
129.Xr timed 8
130.Sh HISTORY
131The
132.Fn gettimeofday
133function call appeared in
134.Bx 4.2 .
135The
136.Va tv_sec
137element of struct timeval is of type time_t since
138.Mx 8 .
139