533b24115dcfe09c3af95a1f8ab178e042650682
[dragonfly.git] / lib / libc / sys / gettimeofday.2
1 .\" Copyright (c) 1980, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)gettimeofday.2      8.2 (Berkeley) 5/26/95
33 .\" $FreeBSD: src/lib/libc/sys/gettimeofday.2,v 1.9.2.9 2003/02/11 06:05:00 nsayer Exp $
34 .\" $DragonFly: src/lib/libc/sys/gettimeofday.2,v 1.3 2006/02/28 02:25:10 swildner Exp $
35 .\"
36 .Dd May 26, 1995
37 .Dt GETTIMEOFDAY 2
38 .Os
39 .Sh NAME
40 .Nm gettimeofday ,
41 .Nm settimeofday
42 .Nd get/set date and time
43 .Sh LIBRARY
44 .Lb libc
45 .Sh SYNOPSIS
46 .In sys/time.h
47 .Ft int
48 .Fn gettimeofday "struct timeval *tp" "struct timezone *tzp"
49 .Ft int
50 .Fn settimeofday "const struct timeval *tp" "const struct timezone *tzp"
51 .Sh DESCRIPTION
52 .Bf -symbolic
53 Note: timezone is no longer used; this information is kept outside
54 the kernel.
55 .Ef
56 .Pp
57 The system's notion of the current Greenwich time and the current time
58 zone is obtained with the
59 .Fn gettimeofday
60 call, and set with the
61 .Fn settimeofday
62 call.  The time is expressed in seconds and microseconds
63 since midnight (0 hour), January 1, 1970.  The resolution of the system
64 clock is hardware dependent, and the time may be updated continuously or
65 in
66 .Dq ticks .
67 If
68 .Fa tp
69 or
70 .Fa tzp
71 is NULL, the associated time
72 information will not be returned or set.
73 .Pp
74 The structures pointed to by
75 .Fa tp
76 and
77 .Fa tzp
78 are defined in
79 .Ao Pa sys/time.h Ac
80 as:
81 .Pp
82 .Bd -literal
83 struct timeval {
84         long    tv_sec;         /* seconds since Jan. 1, 1970 */
85         long    tv_usec;        /* and microseconds */
86 };
87
88 struct timezone {
89         int     tz_minuteswest; /* minutes west of Greenwich */
90         int     tz_dsttime;     /* type of dst correction */
91 };
92 .Ed
93 .Pp
94 The
95 .Fa timezone
96 structure indicates the local time zone
97 (measured in minutes of time westward from Greenwich),
98 and a flag that, if nonzero, indicates that
99 Daylight Saving time applies locally during
100 the appropriate part of the year.
101 .Pp
102 Only the super-user may set the time of day or time zone.
103 If the system is running at securelevel \(>= 2 (see
104 .Xr init 8 ) ,
105 the time may only be advanced or retarded by a maximum of one second.
106 This limitation is imposed to prevent a malicious super-user
107 from setting arbitrary time stamps on files.
108 The system time can be adjusted backwards without restriction using the
109 .Xr adjtime 2
110 system call even when the system is secure.
111 .Sh RETURN VALUES
112 .Rv -std
113 .Sh ERRORS
114 The following error codes may be set in
115 .Va errno :
116 .Bl -tag -width Er
117 .It Bq Er EFAULT
118 An argument address referenced invalid memory.
119 .It Bq Er EPERM
120 A user other than the super-user attempted to set the time.
121 .El
122 .Sh SEE ALSO
123 .Xr date 1 ,
124 .Xr adjtime 2 ,
125 .Xr ctime 3 ,
126 .Xr clocks 7 ,
127 .Xr timed 8
128 .Sh HISTORY
129 The
130 .Fn gettimeofday
131 function call appeared in
132 .Bx 4.2 .