]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/gettimeofday.2
user_namespaces.7: Minor wording fix to recently added text
[thirdparty/man-pages.git] / man2 / gettimeofday.2
CommitLineData
fea681da
MK
1.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
c13182ef 12.\"
fea681da
MK
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.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
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.
c11b1abf 37.\" Modified, 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da
MK
38.\" Added notes on capability requirement.
39.\"
9ba01802 40.TH GETTIMEOFDAY 2 2019-03-06 "Linux" "Linux Programmer's Manual"
fea681da
MK
41.SH NAME
42gettimeofday, settimeofday \- get / set time
43.SH SYNOPSIS
a028f2ed 44.nf
fea681da 45.B #include <sys/time.h>
dbfe9c70 46.PP
fea681da 47.BI "int gettimeofday(struct timeval *" tv ", struct timezone *" tz );
dbfe9c70 48.PP
a028f2ed
MK
49.BI "int settimeofday(const struct timeval *" tv \
50", const struct timezone *" tz );
a028f2ed 51.fi
dbfe9c70 52.PP
cc4615cc
MK
53.in -4n
54Feature Test Macro Requirements for glibc (see
55.BR feature_test_macros (7)):
56.in
68e4db0a 57.PP
cc4615cc 58.BR settimeofday ():
51c612fb
MK
59 Since glibc 2.19:
60 _DEFAULT_SOURCE
61 Glibc 2.19 and earlier:
62 _BSD_SOURCE
fea681da
MK
63.SH DESCRIPTION
64The functions
e511ffb6 65.BR gettimeofday ()
fea681da 66and
e511ffb6 67.BR settimeofday ()
fea681da 68can get and set the time as well as a timezone.
c13182ef 69The
fea681da 70.I tv
c13182ef
MK
71argument is a
72.I struct timeval
0425de01 73(as specified in
8478ee02 74.IR <sys/time.h> ):
51f5698d 75.PP
a08ea57c 76.in +4n
58c2a94b 77.EX
fea681da 78struct timeval {
1c382af4
MK
79 time_t tv_sec; /* seconds */
80 suseconds_t tv_usec; /* microseconds */
fea681da 81};
58c2a94b 82.EE
a08ea57c 83.in
51f5698d 84.PP
fea681da
MK
85and gives the number of seconds and microseconds since the Epoch (see
86.BR time (2)).
c13182ef 87The
fea681da 88.I tz
c13182ef 89argument is a
8478ee02 90.IR "struct timezone" :
51f5698d 91.PP
a08ea57c 92.in +4n
58c2a94b 93.EX
fea681da 94struct timezone {
79893ac3
MK
95 int tz_minuteswest; /* minutes west of Greenwich */
96 int tz_dsttime; /* type of DST correction */
fea681da 97};
58c2a94b 98.EE
a08ea57c 99.in
1c382af4
MK
100.PP
101If either
102.I tv
c13182ef 103or
1c382af4
MK
104.I tz
105is NULL, the corresponding structure is not set or returned.
bea08fec 106.\" FIXME . The compilation warning looks to be going away in 2.17
f70f94e8 107.\" see glibc commit 4b7634a5e03b0da6f8875de9d3f74c1cf6f2a6e8
f1e90ec4
MK
108(However, compilation warnings will result if
109.I tv
110is NULL.)
1c382af4
MK
111.\" The following is covered under EPERM below:
112.\" .PP
113.\" Only the superuser may use
114.\" .BR settimeofday ().
fea681da 115.PP
c13182ef
MK
116The use of the
117.I timezone
1c382af4
MK
118structure is obsolete; the
119.I tz
7145b9a9 120argument should normally be specified as NULL.
d5c4e197 121(See NOTES below.)
efeece04 122.PP
eb9a0b2f 123Under Linux, there are some peculiar "warp clock" semantics associated
d2296c22 124with the
e511ffb6 125.BR settimeofday ()
fea681da
MK
126system call if on the very first call (after booting)
127that has a non-NULL
128.I tz
129argument, the
130.I tv
131argument is NULL and the
132.I tz_minuteswest
c7094399 133field is nonzero.
d5c4e197
MK
134(The
135.I tz_dsttime
136field should be zero for this case.)
c13182ef 137In such a case it is assumed that the CMOS clock
fea681da
MK
138is on local time, and that it has to be incremented by this amount
139to get UTC system time.
140No doubt it is a bad idea to use this feature.
47297adb 141.SH RETURN VALUE
e511ffb6 142.BR gettimeofday ()
fea681da 143and
e511ffb6 144.BR settimeofday ()
fea681da
MK
145return 0 for success, or \-1 for failure (in which case
146.I errno
147is set appropriately).
148.SH ERRORS
149.TP
150.B EFAULT
c13182ef 151One of
fea681da
MK
152.I tv
153or
154.I tz
155pointed outside the accessible address space.
156.TP
157.B EINVAL
9a82d4d9
MK
158.RB ( settimeofday ()):
159.I timezone
160is invalid.
fea681da 161.TP
018c296c
MK
162.B EINVAL
163.RB ( settimeofday ()):
164.I tv.tv_sec
165is negative or
166.I tv.tv_usec
167is outside the range [0..999,999].
168.TP
bccacb94
MK
169.BR EINVAL " (since Linux 4.3)"
170.\" commit e1d7ba8735551ed79c7a0463a042353574b96da3
171.RB ( settimeofday ()):
172An attempt was made to set the time to a value less than
173the current value of the
174.B CLOCK_MONOTONIC
175clock (see
176.BR clock_gettime (2)).
177.TP
fea681da 178.B EPERM
c13182ef 179The calling process has insufficient privilege to call
e511ffb6 180.BR settimeofday ();
fea681da
MK
181under Linux the
182.B CAP_SYS_TIME
183capability is required.
47297adb 184.SH CONFORMING TO
a1d5f77c
MK
185SVr4, 4.3BSD.
186POSIX.1-2001 describes
187.BR gettimeofday ()
188but not
189.BR settimeofday ().
f428c08a
MK
190POSIX.1-2008 marks
191.BR gettimeofday ()
4c9f4bc8 192as obsolete, recommending the use of
3f372391
MK
193.BR clock_gettime (2)
194instead.
19c98696 195.SH NOTES
5f04b948 196The time returned by
77b28318 197.BR gettimeofday ()
5f04b948
MK
198.I is
199affected by discontinuous jumps in the system time
200(e.g., if the system administrator manually changes the system time).
201If you need a monotonically increasing clock, see
202.BR clock_gettime (2).
efeece04 203.PP
d5c4e197
MK
204Macros for operating on
205.I timeval
206structures are described in
207.BR timeradd (3).
efeece04 208.PP
c13182ef
MK
209Traditionally, the fields of
210.I struct timeval
e3e25559
MK
211were of type
212.IR long .
53e0c293 213.\"
5e0083d2
MK
214.SS C library/kernel differences
215On some architectures, an implementation of
216.BR gettimeofday ()
217is provided in the
218.BR vdso (7).
219.\"
53e0c293 220.SS The tz_dsttime field
43d6713e
CD
221On a non-Linux kernel, with glibc, the
222.I tz_dsttime
223field of
224.I struct timezone
53e0c293 225will be set to a nonzero value by
43d6713e
CD
226.BR gettimeofday ()
227if the current timezone has ever had or will have a daylight saving
53e0c293
MK
228rule applied.
229In this sense it exactly mirrors the meaning of
43d6713e
CD
230.BR daylight (3)
231for the current zone.
232On Linux, with glibc, the setting of the
d5c4e197 233.I tz_dsttime
43d6713e
CD
234field of
235.I struct timezone
236has never been used by
237.BR settimeofday ()
238or
239.BR gettimeofday ().
d5c4e197
MK
240.\" it has not
241.\" been and will not be supported by libc or glibc.
242.\" Each and every occurrence of this field in the kernel source
243.\" (other than the declaration) is a bug.
53e0c293 244Thus, the following is purely of historical interest.
efeece04 245.PP
d5c4e197
MK
246On old systems, the field
247.I tz_dsttime
248contains a symbolic constant (values are given below)
249that indicates in which part of the year Daylight Saving Time
250is in force.
251(Note: this value is constant throughout the year:
252it does not indicate that DST is in force, it just selects an
253algorithm.)
254The daylight saving time algorithms defined are as follows:
58c2a94b 255.PP
d5c4e197 256.in +4n
58c2a94b 257.EX
d5c4e197 258\fBDST_NONE\fP /* not on DST */
d5c4e197 259\fBDST_USA\fP /* USA style DST */
d5c4e197 260\fBDST_AUST\fP /* Australian style DST */
d5c4e197 261\fBDST_WET\fP /* Western European DST */
d5c4e197 262\fBDST_MET\fP /* Middle European DST */
d5c4e197 263\fBDST_EET\fP /* Eastern European DST */
d5c4e197 264\fBDST_CAN\fP /* Canada */
d5c4e197 265\fBDST_GB\fP /* Great Britain and Eire */
d5c4e197 266\fBDST_RUM\fP /* Romania */
d5c4e197 267\fBDST_TUR\fP /* Turkey */
d5c4e197 268\fBDST_AUSTALT\fP /* Australian style with shift in 1986 */
58c2a94b 269.EE
d5c4e197
MK
270.in
271.PP
272Of course it turned out that the period in which
273Daylight Saving Time is in force cannot be given
274by a simple algorithm, one per country; indeed,
275this period is determined by unpredictable political
276decisions.
277So this method of representing timezones
278has been abandoned.
47297adb 279.SH SEE ALSO
fea681da
MK
280.BR date (1),
281.BR adjtimex (2),
fb6fc612 282.BR clock_gettime (2),
fea681da
MK
283.BR time (2),
284.BR ctime (3),
285.BR ftime (3),
d5c4e197 286.BR timeradd (3),
eafd5ce1 287.BR capabilities (7),
7032b90a 288.BR time (7),
1ce611a3
MK
289.BR vdso (7),
290.BR hwclock (8)