xref: /original-bsd/lib/libc/sys/gettimeofday.2 (revision 2d1a7683)
1.\" Copyright (c) 1980, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)gettimeofday.2	6.11 (Berkeley) 03/10/91
7.\"
8.Dd
9.Dt GETTIMEOFDAY 2
10.Os BSD 4
11.Sh NAME
12.Nm gettimeofday ,
13.Nm settimeofday
14.Nd get/set date and time
15.Sh SYNOPSIS
16.Fd #include <sys/time.h>
17.Ft int
18.Fn gettimeofday "struct timeval *tp" "struct timezone *tzp"
19.Ft int
20.Fn settimeofday "struct timeval *tp" "struct timezone *tzp"
21.Sh DESCRIPTION
22.Bf -symbolic
23Note: timezone is no longer used; this information is kept outside
24the kernel.
25.Ef
26The system's notion of the current Greenwich time and the current time
27zone is obtained with the
28.Fn gettimeofday
29call, and set with the
30.Fn settimeofday
31call.  The time is expressed in seconds and microseconds
32since midnight (0 hour), January 1, 1970.  The resolution of the system
33clock is hardware dependent, and the time may be updated continuously or
34in ``ticks.''  If
35.Fa tp
36or
37.Fa tzp
38is NULL, the associated time
39information will not be returned or set.
40.Pp
41The structures pointed to by
42.Fa tp
43and
44.Fa tzp
45are defined in
46.Ao Pa sys/time.h Ac
47as:
48.Pp
49.Bd -literal
50struct timeval {
51	long	tv_sec;		/* seconds since Jan. 1, 1970 */
52	long	tv_usec;	/* and microseconds */
53};
54
55struct timezone {
56	int	tz_minuteswest; /* of Greenwich */
57	int	tz_dsttime;	/* type of dst correction to apply */
58};
59.Ed
60.Pp
61The
62.Fa timezone
63structure indicates the local time zone
64(measured in minutes of time westward from Greenwich),
65and a flag that, if nonzero, indicates that
66Daylight Saving time applies locally during
67the appropriate part of the year.
68.Pp
69Only the super-user may set the time of day or time zone.
70.Sh RETURN
71A 0 return value indicates that the call succeeded.
72A -1 return value indicates an error occurred, and in this
73case an error code is stored into the global variable
74.Va errno .
75.Sh ERRORS
76The following error codes may be set in
77.Va errno :
78.Bl -tag -width [EFAULT]
79.It Bq Er EFAULT
80An argument address referenced invalid memory.
81.It Bq Er EPERM
82A user other than the super-user attempted to set the time.
83.El
84.Sh SEE ALSO
85.Xr date 1 ,
86.Xr adjtime 2 ,
87.Xr ctime 3 ,
88.Xr timed 8
89.Sh HISTORY
90The
91.Nm
92function call appeared in
93.Bx 4.2 .
94