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