xref: /freebsd/lib/libsys/gettimeofday.2 (revision 6662c231)
18269e767SBrooks Davis.\" Copyright (c) 1980, 1991, 1993
28269e767SBrooks Davis.\"	The Regents of the University of California.  All rights reserved.
38269e767SBrooks Davis.\"
48269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
58269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
68269e767SBrooks Davis.\" are met:
78269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
88269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
98269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
108269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
118269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
128269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors
138269e767SBrooks Davis.\"    may be used to endorse or promote products derived from this software
148269e767SBrooks Davis.\"    without specific prior written permission.
158269e767SBrooks Davis.\"
168269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
178269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
188269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
198269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
208269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
218269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
228269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
238269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
248269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
258269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
268269e767SBrooks Davis.\" SUCH DAMAGE.
278269e767SBrooks Davis.\"
286662c231SMateusz Piotrowski.Dd April 28, 2024
298269e767SBrooks Davis.Dt GETTIMEOFDAY 2
308269e767SBrooks Davis.Os
318269e767SBrooks Davis.Sh NAME
328269e767SBrooks Davis.Nm gettimeofday ,
338269e767SBrooks Davis.Nm settimeofday
348269e767SBrooks Davis.Nd get/set date and time
358269e767SBrooks Davis.Sh LIBRARY
368269e767SBrooks Davis.Lb libc
378269e767SBrooks Davis.Sh SYNOPSIS
388269e767SBrooks Davis.In sys/time.h
398269e767SBrooks Davis.Ft int
408269e767SBrooks Davis.Fn gettimeofday "struct timeval *tp" "struct timezone *tzp"
418269e767SBrooks Davis.Ft int
428269e767SBrooks Davis.Fn settimeofday "const struct timeval *tp" "const struct timezone *tzp"
438269e767SBrooks Davis.Sh DESCRIPTION
444395d3ceSMateusz Piotrowski.Em Note :
454395d3ceSMateusz PiotrowskiThe
464395d3ceSMateusz Piotrowski.Nm gettimeofday
474395d3ceSMateusz Piotrowskifunction
484395d3ceSMateusz Piotrowski.Po but not
494395d3ceSMateusz Piotrowski.Nm settimeofday Pc
504395d3ceSMateusz Piotrowskiis obsolescent.
514395d3ceSMateusz PiotrowskiSee the
524395d3ceSMateusz Piotrowski.Sx STANDARDS
534395d3ceSMateusz Piotrowskisection for more details.
544395d3ceSMateusz Piotrowski.Pp
558269e767SBrooks DavisThe system's notion of the current Greenwich time and the current time
568269e767SBrooks Daviszone is obtained with the
578269e767SBrooks Davis.Fn gettimeofday
588269e767SBrooks Davissystem call, and set with the
598269e767SBrooks Davis.Fn settimeofday
608269e767SBrooks Davissystem call.
618269e767SBrooks DavisThe time is expressed in seconds and microseconds
628269e767SBrooks Davissince midnight (0 hour), January 1, 1970.
638269e767SBrooks DavisThe resolution of the system
648269e767SBrooks Davisclock is hardware dependent, and the time may be updated continuously or
658269e767SBrooks Davisin
668269e767SBrooks Davis.Dq ticks .
678269e767SBrooks DavisIf
688269e767SBrooks Davis.Fa tp
698269e767SBrooks Davisor
708269e767SBrooks Davis.Fa tzp
718269e767SBrooks Davisis NULL, the associated time
728269e767SBrooks Davisinformation will not be returned or set.
738269e767SBrooks Davis.Pp
748269e767SBrooks DavisThe structures pointed to by
758269e767SBrooks Davis.Fa tp
768269e767SBrooks Davisand
778269e767SBrooks Davis.Fa tzp
788269e767SBrooks Davisare defined in
798269e767SBrooks Davis.In sys/time.h
808269e767SBrooks Davisas:
818269e767SBrooks Davis.Bd -literal
828269e767SBrooks Davisstruct timeval {
838269e767SBrooks Davis	time_t		tv_sec;		/* seconds */
848269e767SBrooks Davis	suseconds_t	tv_usec;	/* and microseconds */
858269e767SBrooks Davis};
868269e767SBrooks Davis
878269e767SBrooks Davisstruct timezone {
888269e767SBrooks Davis	int	tz_minuteswest; /* minutes west of Greenwich */
898269e767SBrooks Davis	int	tz_dsttime;	/* type of dst correction */
908269e767SBrooks Davis};
918269e767SBrooks Davis.Ed
928269e767SBrooks Davis.Pp
938269e767SBrooks DavisThe
948269e767SBrooks Davis.Vt timezone
958269e767SBrooks Davisstructure indicates the local time zone
968269e767SBrooks Davis(measured in minutes of time westward from Greenwich),
978269e767SBrooks Davisand a flag that, if nonzero, indicates that
988269e767SBrooks DavisDaylight Saving time applies locally during
998269e767SBrooks Davisthe appropriate part of the year.
1008269e767SBrooks DavisThe kernel generally does not track these values and they
1018269e767SBrooks Davisare usually returned as zero.
1028269e767SBrooks DavisUse
1038269e767SBrooks Davis.Xr localtime 3
1048269e767SBrooks Davisto find the offset for the currently active timezone.
1058269e767SBrooks Davis.Pp
1068269e767SBrooks DavisOnly the super-user may set the time of day or time zone.
1078269e767SBrooks DavisIf the system is running at securelevel >= 2 (see
1088269e767SBrooks Davis.Xr init 8 ) ,
1098269e767SBrooks Davisthe time may only be advanced or retarded by a maximum of one second.
1108269e767SBrooks DavisThis limitation is imposed to prevent a malicious super-user
1118269e767SBrooks Davisfrom setting arbitrary time stamps on files.
1128269e767SBrooks DavisThe system time can be adjusted backwards without restriction using the
1138269e767SBrooks Davis.Xr adjtime 2
1148269e767SBrooks Davissystem call even when the system is secure.
1158269e767SBrooks Davis.Sh RETURN VALUES
1168269e767SBrooks Davis.Rv -std
1178269e767SBrooks Davis.Sh ERRORS
1188269e767SBrooks DavisThe following error codes may be set in
1198269e767SBrooks Davis.Va errno :
1208269e767SBrooks Davis.Bl -tag -width Er
1218269e767SBrooks Davis.It Bq Er EINVAL
1228269e767SBrooks DavisThe supplied
1238269e767SBrooks Davis.Fa timeval
1248269e767SBrooks Davisvalue is invalid.
1258269e767SBrooks Davis.It Bq Er EPERM
1268269e767SBrooks DavisA user other than the super-user attempted to set the time.
1278269e767SBrooks Davis.El
1288269e767SBrooks Davis.Sh SEE ALSO
1298269e767SBrooks Davis.Xr date 1 ,
1308269e767SBrooks Davis.Xr adjtime 2 ,
1318269e767SBrooks Davis.Xr clock_gettime 2 ,
1328269e767SBrooks Davis.Xr ctime 3 ,
1338269e767SBrooks Davis.Xr timeradd 3 ,
1348269e767SBrooks Davis.Xr clocks 7
1354395d3ceSMateusz Piotrowski.Sh STANDARDS
1364395d3ceSMateusz PiotrowskiThe
1374395d3ceSMateusz Piotrowski.Nm gettimeofday
1384395d3ceSMateusz Piotrowskifunction is considered obsolescent and its usage discouraged by
1394395d3ceSMateusz Piotrowski.\" XXX: This should be replaced in the future when an appropriate argument to
1404395d3ceSMateusz Piotrowski.\" the St macro is available: -p1003.1-2017
1414395d3ceSMateusz Piotrowski.No IEEE Std 1003.1-2008, 2017 Edition (\\(LqPOSIX.1\\(Rq) .
1426662c231SMateusz PiotrowskiApplications should use the
1434395d3ceSMateusz Piotrowski.Xr clock_gettime 2
1446662c231SMateusz Piotrowskifunction instead.
1458269e767SBrooks Davis.Sh HISTORY
1468269e767SBrooks DavisThe
1478269e767SBrooks Davis.Fn gettimeofday
1488269e767SBrooks Davissystem call appeared in
1498269e767SBrooks Davis.Bx 4.2 .
150