Initial import from FreeBSD RELENG_4:
[dragonfly.git] / lib / libcr / 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 .\"
35 .Dd May 26, 1995
36 .Dt GETTIMEOFDAY 2
37 .Os
38 .Sh NAME
39 .Nm gettimeofday ,
40 .Nm settimeofday
41 .Nd get/set date and time
42 .Sh LIBRARY
43 .Lb libc
44 .Sh SYNOPSIS
45 .In sys/time.h
46 .Ft int
47 .Fn gettimeofday "struct timeval *tp" "struct timezone *tzp"
48 .Ft int
49 .Fn settimeofday "const struct timeval *tp" "const struct timezone *tzp"
50 .Sh DESCRIPTION
51 .Bf -symbolic
52 Note: timezone is no longer used; this information is kept outside
53 the kernel.
54 .Ef
55 .Pp
56 The system's notion of the current Greenwich time and the current time
57 zone is obtained with the
58 .Fn gettimeofday
59 call, and set with the
60 .Fn settimeofday
61 call.  The time is expressed in seconds and microseconds
62 since midnight (0 hour), January 1, 1970.  The resolution of the system
63 clock is hardware dependent, and the time may be updated continuously or
64 in
65 .Dq ticks .
66 If
67 .Fa tp
68 or
69 .Fa tzp
70 is NULL, the associated time
71 information will not be returned or set.
72 .Pp
73 The structures pointed to by
74 .Fa tp
75 and
76 .Fa tzp
77 are defined in
78 .Ao Pa sys/time.h Ac
79 as:
80 .Pp
81 .Bd -literal
82 struct timeval {
83         long    tv_sec;         /* seconds since Jan. 1, 1970 */
84         long    tv_usec;        /* and microseconds */
85 };
86
87 struct timezone {
88         int     tz_minuteswest; /* minutes west of Greenwich */
89         int     tz_dsttime;     /* type of dst correction */
90 };
91 .Ed
92 .Pp
93 The
94 .Fa timezone
95 structure indicates the local time zone
96 (measured in minutes of time westward from Greenwich),
97 and a flag that, if nonzero, indicates that
98 Daylight Saving time applies locally during
99 the appropriate part of the year.
100 .Pp
101 Only the super-user may set the time of day or time zone.
102 If the system is running at securelevel >= 2 (see
103 .Xr init 8 ) ,
104 the time may only be advanced or retarded by a maximum of one second.
105 This limitation is imposed to prevent a malicious super-user
106 from setting arbitrary time stamps on files.
107 The system time can be adjusted backwards without restriction using the
108 .Xr adjtime 2
109 system call even when the system is secure.
110 .Sh RETURN VALUES
111 .Rv -std
112 .Sh ERRORS
113 The following error codes may be set in
114 .Va errno :
115 .Bl -tag -width Er
116 .It Bq Er EFAULT
117 An argument address referenced invalid memory.
118 .It Bq Er EPERM
119 A user other than the super-user attempted to set the time.
120 .El
121 .Sh SEE ALSO
122 .Xr date 1 ,
123 .Xr adjtime 2 ,
124 .Xr ctime 3 ,
125 .Xr clocks 7 ,
126 .Xr timed 8
127 .Sh HISTORY
128 The
129 .Fn gettimeofday
130 function call appeared in
131 .Bx 4.2 .