xref: /dragonfly/lib/libc/sys/gettimeofday.2 (revision 36a3d1d6)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. 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.\"     @(#)gettimeofday.2	8.2 (Berkeley) 5/26/95
33.\" $FreeBSD: src/lib/libc/sys/gettimeofday.2,v 1.9.2.9 2003/02/11 06:05:00 nsayer Exp $
34.\" $DragonFly: src/lib/libc/sys/gettimeofday.2,v 1.5 2008/05/02 02:05:04 swildner Exp $
35.\"
36.Dd May 26, 1995
37.Dt GETTIMEOFDAY 2
38.Os
39.Sh NAME
40.Nm gettimeofday ,
41.Nm settimeofday
42.Nd get/set date and time
43.Sh LIBRARY
44.Lb libc
45.Sh SYNOPSIS
46.In sys/time.h
47.Ft int
48.Fn gettimeofday "struct timeval *tp" "struct timezone *tzp"
49.Ft int
50.Fn settimeofday "const struct timeval *tp" "const struct timezone *tzp"
51.Sh DESCRIPTION
52.Bf -symbolic
53Note: timezone is no longer used; this information is kept outside
54the kernel.
55.Ef
56.Pp
57The system's notion of the current Greenwich time and the current time
58zone is obtained with the
59.Fn gettimeofday
60call, and set with the
61.Fn settimeofday
62call.  The time is expressed in seconds and microseconds
63since midnight (0 hour), January 1, 1970.  The resolution of the system
64clock is hardware dependent, and the time may be updated continuously or
65in
66.Dq ticks .
67If
68.Fa tp
69or
70.Fa tzp
71is NULL, the 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.In sys/time.h
80as:
81.Bd -literal
82struct timeval {
83	long	tv_sec;		/* seconds since Jan. 1, 1970 */
84	long	tv_usec;	/* and microseconds */
85};
86
87struct timezone {
88	int	tz_minuteswest; /* minutes west of Greenwich */
89	int	tz_dsttime;	/* type of dst correction */
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 super-user may set the time of day or time zone.
102If the system is running at securelevel \(>= 2 (see
103.Xr init 8 ) ,
104the time may only be advanced or retarded by a maximum of one second.
105This limitation is imposed to prevent a malicious super-user
106from setting arbitrary time stamps on files.
107The system time can be adjusted backwards without restriction using the
108.Xr adjtime 2
109system call even when the system is secure.
110.Sh RETURN VALUES
111.Rv -std
112.Sh ERRORS
113The following error codes may be set in
114.Va errno :
115.Bl -tag -width Er
116.It Bq Er EFAULT
117An argument address referenced invalid memory.
118.It Bq Er EPERM
119A user other than the super-user attempted to set the time.
120.El
121.Sh SEE ALSO
122.Xr date 1 ,
123.Xr adjtime 2 ,
124.Xr ctime 3 ,
125.Xr clocks 7 ,
126.Xr timed 8
127.Sh HISTORY
128The
129.Fn gettimeofday
130function call appeared in
131.Bx 4.2 .
132