flag fields are u_int's
[unix-history] / usr / src / lib / libc / sys / gettimeofday.2
CommitLineData
931b8415 1.\" Copyright (c) 1980, 1991 The Regents of the University of California.
88b3ccf2 2.\" All rights reserved.
03365d4a 3.\"
91cff1e1 4.\" %sccs.include.redist.man%
88b3ccf2 5.\"
931b8415 6.\" @(#)gettimeofday.2 6.11 (Berkeley) %G%
03365d4a 7.\"
931b8415
CL
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
1347a72e 26The system's notion of the current Greenwich time and the current time
931b8415
CL
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
1347a72e
KB
32since midnight (0 hour), January 1, 1970. The resolution of the system
33clock is hardware dependent, and the time may be updated continuously or
931b8415
CL
34in ``ticks.'' If
35.Fa tp
36or
37.Fa tzp
38is NULL, the associated time
1347a72e 39information will not be returned or set.
931b8415 40.Pp
a2364113 41The structures pointed to by
931b8415 42.Fa tp
a2364113 43and
931b8415 44.Fa tzp
a2364113 45are defined in
931b8415 46.Ao Pa sys/time.h Ac
a2364113 47as:
931b8415
CL
48.Pp
49.Bd -literal
a2364113 50struct timeval {
db2c4838 51 long tv_sec; /* seconds since Jan. 1, 1970 */
931b8415 52 long tv_usec; /* and microseconds */
a2364113 53};
931b8415 54
a2364113 55struct timezone {
931b8415 56 int tz_minuteswest; /* of Greenwich */
a2364113
KM
57 int tz_dsttime; /* type of dst correction to apply */
58};
931b8415
CL
59.Ed
60.Pp
a2364113 61The
931b8415 62.Fa timezone
a2364113
KM
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.
931b8415 68.Pp
db2c4838 69Only the super-user may set the time of day or time zone.
931b8415 70.Sh RETURN
a2364113 71A 0 return value indicates that the call succeeded.
931b8415
CL
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
a2364113 80An argument address referenced invalid memory.
931b8415 81.It Bq Er EPERM
a2364113 82A user other than the super-user attempted to set the time.
931b8415
CL
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 .