]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/gettimeofday.2
Changes: Ready for 4.09
[thirdparty/man-pages.git] / man2 / gettimeofday.2
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified by Michael Haardt (michael@moria.de)
26 .\" Modified 1993-07-23 by Rik Faith (faith@cs.unc.edu)
27 .\" Modified 1994-08-21 by Michael Chastain (mec@shell.portal.com):
28 .\" Fixed necessary '#include' lines.
29 .\" Modified 1995-04-15 by Michael Chastain (mec@shell.portal.com):
30 .\" Added reference to adjtimex.
31 .\" Removed some nonsense lines pointed out by Urs Thuermann,
32 .\" (urs@isnogud.escape.de), aeb, 950722.
33 .\" Modified 1997-01-14 by Austin Donnelly (and1000@debian.org):
34 .\" Added return values section, and bit on EFAULT
35 .\" Added clarification on timezone, aeb, 971210.
36 .\" Removed "#include <unistd.h>", aeb, 010316.
37 .\" Modified, 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
38 .\" Added notes on capability requirement.
39 .\"
40 .TH GETTIMEOFDAY 2 2016-03-15 "Linux" "Linux Programmer's Manual"
41 .SH NAME
42 gettimeofday, settimeofday \- get / set time
43 .SH SYNOPSIS
44 .nf
45 .B #include <sys/time.h>
46
47 .BI "int gettimeofday(struct timeval *" tv ", struct timezone *" tz );
48
49 .BI "int settimeofday(const struct timeval *" tv \
50 ", const struct timezone *" tz );
51
52 .fi
53 .in -4n
54 Feature Test Macro Requirements for glibc (see
55 .BR feature_test_macros (7)):
56 .in
57 .sp
58 .BR settimeofday ():
59 Since glibc 2.19:
60 _DEFAULT_SOURCE
61 Glibc 2.19 and earlier:
62 _BSD_SOURCE
63 .SH DESCRIPTION
64 The functions
65 .BR gettimeofday ()
66 and
67 .BR settimeofday ()
68 can get and set the time as well as a timezone.
69 The
70 .I tv
71 argument is a
72 .I struct timeval
73 (as specified in
74 .IR <sys/time.h> ):
75 .sp
76 .in +4n
77 .nf
78 struct timeval {
79 time_t tv_sec; /* seconds */
80 suseconds_t tv_usec; /* microseconds */
81 };
82 .fi
83 .in
84 .sp
85 and gives the number of seconds and microseconds since the Epoch (see
86 .BR time (2)).
87 The
88 .I tz
89 argument is a
90 .IR "struct timezone" :
91 .sp
92 .in +4n
93 .nf
94 struct timezone {
95 int tz_minuteswest; /* minutes west of Greenwich */
96 int tz_dsttime; /* type of DST correction */
97 };
98 .fi
99 .in
100 .PP
101 If either
102 .I tv
103 or
104 .I tz
105 is NULL, the corresponding structure is not set or returned.
106 .\" FIXME . The compilation warning looks to be going away in 2.17
107 .\" see glibc commit 4b7634a5e03b0da6f8875de9d3f74c1cf6f2a6e8
108 (However, compilation warnings will result if
109 .I tv
110 is NULL.)
111 .\" The following is covered under EPERM below:
112 .\" .PP
113 .\" Only the superuser may use
114 .\" .BR settimeofday ().
115 .PP
116 The use of the
117 .I timezone
118 structure is obsolete; the
119 .I tz
120 argument should normally be specified as NULL.
121 (See NOTES below.)
122
123 Under Linux, there are some peculiar "warp clock" semantics associated
124 with the
125 .BR settimeofday ()
126 system call if on the very first call (after booting)
127 that has a non-NULL
128 .I tz
129 argument, the
130 .I tv
131 argument is NULL and the
132 .I tz_minuteswest
133 field is nonzero.
134 (The
135 .I tz_dsttime
136 field should be zero for this case.)
137 In such a case it is assumed that the CMOS clock
138 is on local time, and that it has to be incremented by this amount
139 to get UTC system time.
140 No doubt it is a bad idea to use this feature.
141 .SH RETURN VALUE
142 .BR gettimeofday ()
143 and
144 .BR settimeofday ()
145 return 0 for success, or \-1 for failure (in which case
146 .I errno
147 is set appropriately).
148 .SH ERRORS
149 .TP
150 .B EFAULT
151 One of
152 .I tv
153 or
154 .I tz
155 pointed outside the accessible address space.
156 .TP
157 .B EINVAL
158 Timezone (or something else) is invalid.
159 .TP
160 .B EPERM
161 The calling process has insufficient privilege to call
162 .BR settimeofday ();
163 under Linux the
164 .B CAP_SYS_TIME
165 capability is required.
166 .SH CONFORMING TO
167 SVr4, 4.3BSD.
168 POSIX.1-2001 describes
169 .BR gettimeofday ()
170 but not
171 .BR settimeofday ().
172 POSIX.1-2008 marks
173 .BR gettimeofday ()
174 as obsolete, recommending the use of
175 .BR clock_gettime (2)
176 instead.
177 .SH NOTES
178 The time returned by
179 .BR gettimeofday ()
180 .I is
181 affected by discontinuous jumps in the system time
182 (e.g., if the system administrator manually changes the system time).
183 If you need a monotonically increasing clock, see
184 .BR clock_gettime (2).
185
186 Macros for operating on
187 .I timeval
188 structures are described in
189 .BR timeradd (3).
190
191 Traditionally, the fields of
192 .I struct timeval
193 were of type
194 .IR long .
195 .\"
196 .SS The tz_dsttime field
197 On a non-Linux kernel, with glibc, the
198 .I tz_dsttime
199 field of
200 .I struct timezone
201 will be set to a nonzero value by
202 .BR gettimeofday ()
203 if the current timezone has ever had or will have a daylight saving
204 rule applied.
205 In this sense it exactly mirrors the meaning of
206 .BR daylight (3)
207 for the current zone.
208 On Linux, with glibc, the setting of the
209 .I tz_dsttime
210 field of
211 .I struct timezone
212 has never been used by
213 .BR settimeofday ()
214 or
215 .BR gettimeofday ().
216 .\" it has not
217 .\" been and will not be supported by libc or glibc.
218 .\" Each and every occurrence of this field in the kernel source
219 .\" (other than the declaration) is a bug.
220 Thus, the following is purely of historical interest.
221
222 On old systems, the field
223 .I tz_dsttime
224 contains a symbolic constant (values are given below)
225 that indicates in which part of the year Daylight Saving Time
226 is in force.
227 (Note: this value is constant throughout the year:
228 it does not indicate that DST is in force, it just selects an
229 algorithm.)
230 The daylight saving time algorithms defined are as follows:
231 .in +4n
232 .nf
233
234 \fBDST_NONE\fP /* not on DST */
235 .br
236 \fBDST_USA\fP /* USA style DST */
237 .br
238 \fBDST_AUST\fP /* Australian style DST */
239 .br
240 \fBDST_WET\fP /* Western European DST */
241 .br
242 \fBDST_MET\fP /* Middle European DST */
243 .br
244 \fBDST_EET\fP /* Eastern European DST */
245 .br
246 \fBDST_CAN\fP /* Canada */
247 .br
248 \fBDST_GB\fP /* Great Britain and Eire */
249 .br
250 \fBDST_RUM\fP /* Romania */
251 .br
252 \fBDST_TUR\fP /* Turkey */
253 .br
254 \fBDST_AUSTALT\fP /* Australian style with shift in 1986 */
255 .fi
256 .in
257 .PP
258 Of course it turned out that the period in which
259 Daylight Saving Time is in force cannot be given
260 by a simple algorithm, one per country; indeed,
261 this period is determined by unpredictable political
262 decisions.
263 So this method of representing timezones
264 has been abandoned.
265 .SH SEE ALSO
266 .BR date (1),
267 .BR adjtimex (2),
268 .BR clock_gettime (2),
269 .BR time (2),
270 .BR ctime (3),
271 .BR ftime (3),
272 .BR timeradd (3),
273 .BR capabilities (7),
274 .BR time (7),
275 .BR vdso (7),
276 .BR hwclock (8)