-
Notifications
You must be signed in to change notification settings - Fork 0
/
gettimeofday.html
305 lines (233 loc) · 8.95 KB
/
gettimeofday.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:26:03 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>GETTIMEOFDAY</title>
</head>
<body>
<h1 align="center">GETTIMEOFDAY</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">gettimeofday,
settimeofday - get / set time</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<sys/time.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
gettimeofday(struct timeval *</b><i>tv</i><b>, struct
timezone *</b><i>tz</i><b>);</b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
settimeofday(const struct timeval *</b><i>tv</i><b>, const
struct timezone *</b><i>tz</i><b>);</b></p>
<p style="margin-left:5%; margin-top: 1em">Feature Test
Macro Requirements for glibc (see
<b>feature_test_macros</b>(7)):</p>
<p style="margin-left:11%; margin-top: 1em"><b>settimeofday</b>():
<br>
Since glibc 2.19: <br>
_DEFAULT_SOURCE <br>
Glibc 2.19 and earlier: <br>
_BSD_SOURCE</p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">The functions
<b>gettimeofday</b>() and <b>settimeofday</b>() can get and
set the time as well as a timezone. The <i>tv</i> argument
is a <i>struct timeval</i> (as specified in
<i><sys/time.h></i>):</p>
<p style="margin-left:17%; margin-top: 1em">struct timeval
{ <br>
time_t tv_sec; /* seconds */ <br>
suseconds_t tv_usec; /* microseconds */ <br>
};</p>
<p style="margin-left:11%; margin-top: 1em">and gives the
number of seconds and microseconds since the Epoch (see
<b>time</b>(2)). The <i>tz</i> argument is a <i>struct
timezone</i>:</p>
<p style="margin-left:17%; margin-top: 1em">struct timezone
{ <br>
int tz_minuteswest; /* minutes west of Greenwich */ <br>
int tz_dsttime; /* type of DST correction */ <br>
};</p>
<p style="margin-left:11%; margin-top: 1em">If either
<i>tv</i> or <i>tz</i> is NULL, the corresponding structure
is not set or returned. (However, compilation warnings will
result if <i>tv</i> is NULL.)</p>
<p style="margin-left:11%; margin-top: 1em">The use of the
<i>timezone</i> structure is obsolete; the <i>tz</i>
argument should normally be specified as NULL. (See NOTES
below.)</p>
<p style="margin-left:11%; margin-top: 1em">Under Linux,
there are some peculiar "warp clock" semantics
associated with the <b>settimeofday</b>() system call if on
the very first call (after booting) that has a non-NULL
<i>tz</i> argument, the <i>tv</i> argument is NULL and the
<i>tz_minuteswest</i> field is nonzero. (The
<i>tz_dsttime</i> field should be zero for this case.) In
such a case it is assumed that the CMOS clock is on local
time, and that it has to be incremented by this amount to
get UTC system time. No doubt it is a bad idea to use this
feature.</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>gettimeofday</b>()
and <b>settimeofday</b>() return 0 for success, or -1 for
failure (in which case <i>errno</i> is set
appropriately).</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>EFAULT</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">One of <i>tv</i> or <i>tz</i>
pointed outside the accessible address space.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>(<b>settimeofday</b>()): <i>timezone</i> is invalid.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>(<b>settimeofday</b>()): <i>tv.tv_sec</i> is negative or
<i>tv.tv_usec</i> is outside the range [0..999,999].</p></td></tr>
</table>
<p style="margin-left:11%;"><b>EINVAL</b> (since Linux
4.3)</p>
<p style="margin-left:22%;">(<b>settimeofday</b>()): An
attempt was made to set the time to a value less than the
current value of the <b>CLOCK_MONOTONIC</b> clock (see
<b>clock_gettime</b>(2)).</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="7%">
<p><b>EPERM</b></p></td>
<td width="4%"></td>
<td width="78%">
<p>The calling process has insufficient privilege to call
<b>settimeofday</b>(); under Linux the <b>CAP_SYS_TIME</b>
capability is required.</p></td></tr>
</table>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">SVr4, 4.3BSD.
POSIX.1-2001 describes <b>gettimeofday</b>() but not
<b>settimeofday</b>(). POSIX.1-2008 marks
<b>gettimeofday</b>() as obsolete, recommending the use of
<b>clock_gettime</b>(2) instead.</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">The time
returned by <b>gettimeofday</b>() <i>is</i> affected by
discontinuous jumps in the system time (e.g., if the system
administrator manually changes the system time). If you need
a monotonically increasing clock, see
<b>clock_gettime</b>(2).</p>
<p style="margin-left:11%; margin-top: 1em">Macros for
operating on <i>timeval</i> structures are described in
<b>timeradd</b>(3).</p>
<p style="margin-left:11%; margin-top: 1em">Traditionally,
the fields of <i>struct timeval</i> were of type
<i>long</i>.</p>
<p style="margin-left:11%; margin-top: 1em"><b>C
library/kernel differences</b> <br>
On some architectures, an implementation of
<b>gettimeofday</b>() is provided in the <b>vdso</b>(7).</p>
<p style="margin-left:11%; margin-top: 1em"><b>The
tz_dsttime field</b> <br>
On a non-Linux kernel, with glibc, the <i>tz_dsttime</i>
field of <i>struct timezone</i> will be set to a nonzero
value by <b>gettimeofday</b>() if the current timezone has
ever had or will have a daylight saving rule applied. In
this sense it exactly mirrors the meaning of
<b>daylight</b>(3) for the current zone. On Linux, with
glibc, the setting of the <i>tz_dsttime</i> field of
<i>struct timezone</i> has never been used by
<b>settimeofday</b>() or <b>gettimeofday</b>(). Thus, the
following is purely of historical interest.</p>
<p style="margin-left:11%; margin-top: 1em">On old systems,
the field <i>tz_dsttime</i> contains a symbolic constant
(values are given below) that indicates in which part of the
year Daylight Saving Time is in force. (Note: this value is
constant throughout the year: it does not indicate that DST
is in force, it just selects an algorithm.) The daylight
saving time algorithms defined are as follows:</p>
<p style="margin-left:17%; margin-top: 1em"><b>DST_NONE</b>
/* not on DST */ <b><br>
DST_USA</b> /* USA style DST */ <b><br>
DST_AUST</b> /* Australian style DST */ <b><br>
DST_WET</b> /* Western European DST */ <b><br>
DST_MET</b> /* Middle European DST */ <b><br>
DST_EET</b> /* Eastern European DST */ <b><br>
DST_CAN</b> /* Canada */ <b><br>
DST_GB</b> /* Great Britain and Eire */ <b><br>
DST_RUM</b> /* Romania */ <b><br>
DST_TUR</b> /* Turkey */ <b><br>
DST_AUSTALT</b> /* Australian style with shift in 1986
*/</p>
<p style="margin-left:11%; margin-top: 1em">Of course it
turned out that the period in which Daylight Saving Time is
in force cannot be given by a simple algorithm, one per
country; indeed, this period is determined by unpredictable
political decisions. So this method of representing
timezones has been abandoned.</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>date</b>(1),
<b>adjtimex</b>(2), <b>clock_gettime</b>(2), <b>time</b>(2),
<b>ctime</b>(3), <b>ftime</b>(3), <b>timeradd</b>(3),
<b>capabilities</b>(7), <b>time</b>(7), <b>vdso</b>(7),
<b>hwclock</b>(8)</p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>