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
|
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Modified by Michael Haardt (michael@moria.de)
.\" Modified Fri Jul 23 21:26:27 1993 by Rik Faith (faith@cs.unc.edu)
.\" Modified 21 Aug 1994 by Michael Chastain (mec@shell.portal.com):
.\" Fixed necessary '#include' lines.
.\" Modified 15 Apr 1995 by Michael Chastain (mec@shell.portal.com):
.\" Added reference to adjtimex.
.\" Removed some nonsense lines pointed out by Urs Thuermann,
.\" (urs@isnogud.escape.de), aeb, 950722.
.\" Modified 14 Jan 1997 by Austin Donnelly (and1000@debian.org):
.\" Added return values section, and bit on EFAULT
.\" Added clarification on timezone, aeb, 971210.
.\"
.TH GETTIMEOFDAY 2 "10 December 1997" "Linux 2.0.32" "Linux Programmer's Manual"
.SH NAME
gettimeofday, settimeofday \- get / set time
.SH SYNOPSIS
.B #include <sys/time.h>
.br
.B #include <unistd.h>
.sp
.BI "int gettimeofday(struct timeval *" tv ", struct timezone *" tz );
.br
.BI "int settimeofday(const struct timeval *" tv
.BI ", const struct timezone *" tz );
.SH DESCRIPTION
.B gettimeofday
and
.B settimeofday
can set the time as well as a timezone.
.I tv
is a
.B timeval
struct, as specified in /usr/include/sys/time.h:
.sp
.nf
struct timeval {
.in +8
long tv_sec; /* seconds */
long tv_usec; /* microseconds */
.in -8
};
.fi
.PP
.sp
and
.I tz
is a
.B timezone
:
.sp
.nf
struct timezone {
.in +8
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
.in -8
};
.fi
.PP
The use of the timezone struct is obsolete; the
.I tz_dsttime
field has never been used under Linux - it has not
been and will not be supported by libc or glibc.
Each and every occurrence of this field in the kernel source
(other than the declaration) is a bug. Thus, the following
is purely of historic interest.
The field
.I tz_dsttime
contains a symbolic constant (values are given below)
that indicates in which part of the year Daylight Saving Time
is in force. (Note: its 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 :
.PP
.ta 14
\fB DST_NONE\fP /* not on dst */
.br
\fB DST_USA\fP /* USA style dst */
.br
\fB DST_AUST\fP /* Australian style dst */
.br
\fB DST_WET\fP /* Western European dst */
.br
\fB DST_MET\fP /* Middle European dst */
.br
\fB DST_EET\fP /* Eastern European dst */
.br
\fB DST_CAN\fP /* Canada */
.br
\fB DST_GB\fP /* Great Britain and Eire */
.br
\fB DST_RUM\fP /* Rumania */
.br
\fB DST_TUR\fP /* Turkey */
.br
\fB DST_AUSTALT\fP /* Australian style with shift in 1986 */
.PP
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 time zones
has been abandoned. Under Linux, in a call to
.B settimeofday
the
.I tz_dsttime
field should be zero.
.PP
Under Linux there is some peculiar `warp clock' semantics associated
to the
.B settimeofday
system call if on the very first call (after booting)
that has a non-NULL
.I tz
argument, the
.I tv
argument is NULL and the
.I tz_minuteswest
field is nonzero. 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.
.PP
The following macros are defined to operate on a struct timeval :
.br
.nf
#define timerisset(tvp)\\
.ti +8
((tvp)->tv_sec || (tvp)->tv_usec)
#define timercmp(tvp, uvp, cmp)\\
.in +8
((tvp)->tv_sec cmp (uvp)->tv_sec ||\\
(tvp)->tv_sec == (uvp)->tv_sec &&\\
(tvp)->tv_usec cmp (uvp)->tv_usec)
.in -8
#define timerclear(tvp)\\
.ti +8
((tvp)->tv_sec = (tvp)->tv_usec = 0)
.fi
.PP
If either
.I tv
or
.I tz
is null, the corresponding structure is not set or returned.
.PP
Only the super user may use
.BR settimeofday .
.SH "RETURN VALUES"
.B gettimeofday
and
.B settimeofday
return 0 for success, or -1 for failure (in which case
.I errno
is set appropriately).
.SH ERRORS
.TP
.B EPERM
.B settimeofday
is called by someone other than the superuser.
.TP
.B EINVAL
Timezone (or something else) is invalid.
.TP
.B EFAULT
One of
.I tv
or
.I tz
pointed outside your accessible address space.
.SH "CONFORMING TO"
SVr4, BSD 4.3
.SH "SEE ALSO"
.BR date (1),
.BR adjtimex (2),
.BR time (2),
.BR ctime (3),
.BR ftime (3)
|