]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/gettimeofday.2
xnu-1456.1.26.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.\"
b0d623f7 36.Dd August 5, 2008
9bccf70c
A
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
2d21ac55
A
46.Fo gettimeofday
47.Fa "struct timeval *restrict tp"
48.Fa "void *restrict tzp"
49.Fc
9bccf70c 50.Ft int
2d21ac55
A
51.Fo settimeofday
52.Fa "const struct timeval *tp"
53.Fa "const struct timezone *tzp"
54.Fc
9bccf70c 55.Sh DESCRIPTION
9bccf70c
A
56.Ef
57.Pp
58The system's notion of the current Greenwich time and the current time
59zone is obtained with the
60.Fn gettimeofday
61call, and set with the
62.Fn settimeofday
63call. The time is expressed in seconds and microseconds
64since midnight (0 hour), January 1, 1970. The resolution of the system
65clock is hardware dependent, and the time may be updated continuously or
66in ``ticks.'' If
67.Fa tp
b0d623f7
A
68is NULL
69and
9bccf70c 70.Fa tzp
b0d623f7
A
71is non-NULL,
72.Fn gettimeofday
73will populate the timezone struct in
74.Fa tzp .
75If
76.Fa tp
77is non-NULL and
78.Fa tzp
79is NULL, then only the timeval struct in
80.Fa tp
81is populated. If both
82.Fa tp
83and
84.Fa tzp
85are NULL, nothing is returned.
9bccf70c
A
86.Pp
87The structures pointed to by
88.Fa tp
89and
90.Fa tzp
91are defined in
92.Ao Pa sys/time.h Ac
93as:
94.Pp
95.Bd -literal
b0d623f7 96
9bccf70c 97struct timeval {
2d21ac55
A
98 time_t tv_sec; /* seconds since Jan. 1, 1970 */
99 suseconds_t tv_usec; /* and microseconds */
9bccf70c
A
100};
101
102struct timezone {
103 int tz_minuteswest; /* of Greenwich */
104 int tz_dsttime; /* type of dst correction to apply */
105};
b0d623f7 106
9bccf70c
A
107.Ed
108.Pp
109The
2d21ac55
A
110.Fa timeval
111structure specifies a time value in seconds and microseconds.
112The values in
113.Fa timeval
114are opaque types whose length may vary on different machines;
115depending on them to have any given length may lead to errors.
116.Pp
117The
9bccf70c
A
118.Fa timezone
119structure indicates the local time zone
120(measured in minutes of time westward from Greenwich),
121and a flag that, if nonzero, indicates that
122Daylight Saving time applies locally during
123the appropriate part of the year.
124.Pp
125Only the super-user may set the time of day or time zone.
126If the system securelevel is greater than 1 (see
127.Xr init 8 ),
128the time may only be advanced.
129This limitation is imposed to prevent a malicious super-user
130from setting arbitrary time stamps on files.
131The system time can still be adjusted backwards using the
132.Xr adjtime 2
133system call even when the system is secure.
134.Sh RETURN
135A 0 return value indicates that the call succeeded.
136A -1 return value indicates an error occurred, and in this
137case an error code is stored into the global variable
138.Va errno .
139.Sh ERRORS
140The following error codes may be set in
141.Va errno :
142.Bl -tag -width [EFAULT]
143.It Bq Er EFAULT
144An argument address referenced invalid memory.
145.It Bq Er EPERM
146A user other than the super-user attempted to set the time.
147.El
2d21ac55
A
148.Sh LEGACY SYNOPSIS
149.Fd #include <sys/time.h>
150.Pp
151.Ft int
152.br
153.Fo gettimeofday
154.Fa "struct timeval *tp"
155.Fa "struct timezone *tzp"
156.Fc ;
157.Pp
158The type of
159.Fa tzp
160has changed.
9bccf70c
A
161.Sh SEE ALSO
162.Xr date 1 ,
163.Xr adjtime 2 ,
164.Xr ctime 3 ,
2d21ac55 165.Xr compat 5 ,
9bccf70c
A
166.Xr timed 8
167.Sh HISTORY
168The
169.Fn gettimeofday
170function call appeared in
171.Bx 4.2 .