OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / 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 2012-04-26 "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 _BSD_SOURCE
60 .SH DESCRIPTION
61 The functions
62 .BR gettimeofday ()
63 and
64 .BR settimeofday ()
65 can get and set the time as well as a timezone.
66 The
67 .I tv
68 argument is a
69 .I struct timeval
70 (as specified in
71 .IR <sys/time.h> ):
72 .sp
73 .in +4n
74 .nf
75 struct timeval {
76     time_t      tv_sec;     /* seconds */
77     suseconds_t tv_usec;    /* microseconds */
78 };
79 .fi
80 .in
81 .sp
82 and gives the number of seconds and microseconds since the Epoch (see
83 .BR time (2)).
84 The
85 .I tz
86 argument is a
87 .IR "struct timezone" :
88 .sp
89 .in +4n
90 .nf
91 struct timezone {
92     int tz_minuteswest;     /* minutes west of Greenwich */
93     int tz_dsttime;         /* type of DST correction */
94 };
95 .fi
96 .in
97 .PP
98 If either
99 .I tv
100 or
101 .I tz
102 is NULL, the corresponding structure is not set or returned.
103 .\" FIXME . The compilation warning looks to be going away in 2.17
104 .\" see glibc commit 4b7634a5e03b0da6f8875de9d3f74c1cf6f2a6e8
105 (However, compilation warnings will result if
106 .I tv
107 is NULL.)
108 .\" The following is covered under EPERM below:
109 .\" .PP
110 .\" Only the superuser may use
111 .\" .BR settimeofday ().
112 .PP
113 The use of the
114 .I timezone
115 structure is obsolete; the
116 .I tz
117 argument should normally be specified as NULL.
118 (See NOTES below.)
119
120 Under Linux, there are some peculiar "warp clock" semantics associated
121 with the
122 .BR settimeofday ()
123 system call if on the very first call (after booting)
124 that has a non-NULL
125 .I tz
126 argument, the
127 .I tv
128 argument is NULL and the
129 .I tz_minuteswest
130 field is nonzero.
131 (The
132 .I tz_dsttime
133 field should be zero for this case.)
134 In such a case it is assumed that the CMOS clock
135 is on local time, and that it has to be incremented by this amount
136 to get UTC system time.
137 No doubt it is a bad idea to use this feature.
138 .SH RETURN VALUE
139 .BR gettimeofday ()
140 and
141 .BR settimeofday ()
142 return 0 for success, or \-1 for failure (in which case
143 .I errno
144 is set appropriately).
145 .SH ERRORS
146 .TP
147 .B EFAULT
148 One of
149 .I tv
150 or
151 .I tz
152 pointed outside the accessible address space.
153 .TP
154 .B EINVAL
155 Timezone (or something else) is invalid.
156 .TP
157 .B EPERM
158 The calling process has insufficient privilege to call
159 .BR settimeofday ();
160 under Linux the
161 .B CAP_SYS_TIME
162 capability is required.
163 .SH CONFORMING TO
164 SVr4, 4.3BSD.
165 POSIX.1-2001 describes
166 .BR gettimeofday ()
167 but not
168 .BR settimeofday ().
169 POSIX.1-2008 marks
170 .BR gettimeofday ()
171 as obsolete, recommending the use of
172 .BR clock_gettime (2)
173 instead.
174 .SH NOTES
175 The time returned by
176 .BR gettimeofday ()
177 .I is
178 affected by discontinuous jumps in the system time
179 (e.g., if the system administrator manually changes the system time).
180 If you need a monotonically increasing clock, see
181 .BR clock_gettime (2).
182
183 Macros for operating on
184 .I timeval
185 structures are described in
186 .BR timeradd (3).
187
188 Traditionally, the fields of
189 .I struct timeval
190 were of type
191 .IR long .
192
193 The
194 .I tz_dsttime
195 field has never been used under Linux.
196 .\" it has not
197 .\" been and will not be supported by libc or glibc.
198 .\" Each and every occurrence of this field in the kernel source
199 .\" (other than the declaration) is a bug.
200 Thus, the following
201 is purely of historic interest.
202
203 On old systems, the field
204 .I tz_dsttime
205 contains a symbolic constant (values are given below)
206 that indicates in which part of the year Daylight Saving Time
207 is in force.
208 (Note: this value is constant throughout the year:
209 it does not indicate that DST is in force, it just selects an
210 algorithm.)
211 The daylight saving time algorithms defined are as follows:
212 .in +4n
213 .nf
214
215 \fBDST_NONE\fP     /* not on DST */
216 .br
217 \fBDST_USA\fP      /* USA style DST */
218 .br
219 \fBDST_AUST\fP     /* Australian style DST */
220 .br
221 \fBDST_WET\fP      /* Western European DST */
222 .br
223 \fBDST_MET\fP      /* Middle European DST */
224 .br
225 \fBDST_EET\fP      /* Eastern European DST */
226 .br
227 \fBDST_CAN\fP      /* Canada */
228 .br
229 \fBDST_GB\fP       /* Great Britain and Eire */
230 .br
231 \fBDST_RUM\fP      /* Romania */
232 .br
233 \fBDST_TUR\fP      /* Turkey */
234 .br
235 \fBDST_AUSTALT\fP  /* Australian style with shift in 1986 */
236 .fi
237 .in
238 .PP
239 Of course it turned out that the period in which
240 Daylight Saving Time is in force cannot be given
241 by a simple algorithm, one per country; indeed,
242 this period is determined by unpredictable political
243 decisions.
244 So this method of representing timezones
245 has been abandoned.
246 .SH SEE ALSO
247 .BR date (1),
248 .BR adjtimex (2),
249 .BR clock_gettime (2),
250 .BR time (2),
251 .BR ctime (3),
252 .BR ftime (3),
253 .BR timeradd (3),
254 .BR capabilities (7),
255 .BR time (7)
256 .SH COLOPHON
257 This page is part of release 3.79 of the Linux
258 .I man-pages
259 project.
260 A description of the project,
261 information about reporting bugs,
262 and the latest version of this page,
263 can be found at
264 \%http://www.kernel.org/doc/man\-pages/.