1.\" $NetBSD: gettimeofday.2,v 1.19 2002/10/01 18:10:44 wiz Exp $ 2.\" 3.\" Copyright (c) 1980, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by the University of 17.\" California, Berkeley and its contributors. 18.\" 4. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)gettimeofday.2 8.2 (Berkeley) 5/26/95 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.Fd #include \*[Lt]sys/time.h\*[Gt] 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 53Note: time zone information is no longer provided by this interface. 54See 55.Xr localtime 3 56for information on how to retrieve it. 57.Ef 58.Pp 59The system's notion of the current UTC time is obtained with the 60.Fn gettimeofday 61call, and set with the 62.Fn settimeofday 63call. 64The time is expressed in seconds and microseconds 65since midnight (0 hour), January 1, 1970. 66The resolution of the system clock is hardware dependent, 67and the time may be updated continuously or in ``ticks.'' 68If 69.Fa tp 70is NULL, the time will not be returned or set. 71.Pp 72The structures pointed to by 73.Fa tp 74and 75.Fa tzp 76are defined in 77.Ao Pa sys/time.h Ac 78as: 79.Pp 80.Bd -literal 81struct timeval { 82 long tv_sec; /* seconds since Jan. 1, 1970 */ 83 long tv_usec; /* and microseconds */ 84}; 85 86struct timezone { 87 int tz_minuteswest; /* of Greenwich */ 88 int tz_dsttime; /* type of dst correction to apply */ 89}; 90.Ed 91.Pp 92The 93.Fa timezone 94structure is provided only for source compatibility. 95It is ignored by 96.Fn settimeofday , 97and 98.Fn gettimeofday 99will always return zeroes. 100.Pp 101If the calling user is not the super-user, then the 102.Fn settimeofday 103function in the standard C library will try to use the 104.Xr clockctl 4 105device if present, thus making possible for non privileged users to 106set the system time. 107If 108.Xr clockctl 4 109is not present or not accessible, then 110.Fn settimeofday 111reverts to the 112.Fn settimeofday 113system call, which is restricted to the super user. 114.\" XXX uncomment when/if this is put into place! 115.\" If the system is running in secure mode (see 116.\" .Xr init 8 ), 117.\" the time may only be advanced. 118.\" This limitation is imposed to prevent a malicious super user 119.\" from setting arbitrary time stamps on files. 120.\" The system time can still be adjusted backwards using the 121.\" .Xr adjtime 2 122.\" system call even when the system is secure. 123.Sh RETURN VALUES 124A 0 return value indicates that the call succeeded. 125A -1 return value indicates an error occurred, and in this 126case an error code is stored into the global variable 127.Va errno . 128.Sh ERRORS 129The following error codes may be set in 130.Va errno : 131.Bl -tag -width Er 132.It Bq Er EFAULT 133An argument address referenced invalid memory. 134.It Bq Er EPERM 135A user other than the super user attempted to set the time, or the specified 136time was less than the current time, which was not permitted at the current 137security level. 138.El 139.Sh SEE ALSO 140.Xr date 1 , 141.Xr adjtime 2 , 142.Xr ctime 3 , 143.Xr localtime 3 , 144.Xr clockctl 4 , 145.Xr timed 8 146.Sh HISTORY 147The 148.Fn gettimeofday 149function call appeared in 150.Bx 4.2 . 151The 152.Fa tzp 153argument was deprecated in 154.Bx 4.4 155(and many other systems). 156