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