xref: /csrg-svn/lib/libc/sys/gettimeofday.2 (revision 69706)
161181Sbostic.\" Copyright (c) 1980, 1991, 1993
261181Sbostic.\"	The Regents of the University of California.  All rights reserved.
320138Smckusick.\"
443568Strent.\" %sccs.include.redist.man%
520138Smckusick.\"
6*69706Smckusick.\"     @(#)gettimeofday.2	8.2 (Berkeley) 05/26/95
738053Sbostic.\"
847208Scael.Dd
947208Scael.Dt GETTIMEOFDAY 2
1047208Scael.Os BSD 4
1147208Scael.Sh NAME
1247208Scael.Nm gettimeofday ,
1347208Scael.Nm settimeofday
1447208Scael.Nd get/set date and time
1547208Scael.Sh SYNOPSIS
1647208Scael.Fd #include <sys/time.h>
1747208Scael.Ft int
1847208Scael.Fn gettimeofday "struct timeval *tp" "struct timezone *tzp"
1947208Scael.Ft int
2047208Scael.Fn settimeofday "struct timeval *tp" "struct timezone *tzp"
2147208Scael.Sh DESCRIPTION
2247208Scael.Bf -symbolic
2347208ScaelNote: timezone is no longer used; this information is kept outside
2447208Scaelthe kernel.
2547208Scael.Ef
2630889SbosticThe system's notion of the current Greenwich time and the current time
2747208Scaelzone is obtained with the
2847208Scael.Fn gettimeofday
2947208Scaelcall, and set with the
3047208Scael.Fn settimeofday
3147208Scaelcall.  The time is expressed in seconds and microseconds
3230889Sbosticsince midnight (0 hour), January 1, 1970.  The resolution of the system
3330889Sbosticclock is hardware dependent, and the time may be updated continuously or
3447208Scaelin ``ticks.''  If
3547208Scael.Fa tp
3647208Scaelor
3747208Scael.Fa tzp
3847208Scaelis NULL, the associated time
3930889Sbosticinformation will not be returned or set.
4047208Scael.Pp
4120139SmckusickThe structures pointed to by
4247208Scael.Fa tp
4320139Smckusickand
4447208Scael.Fa tzp
4520139Smckusickare defined in
4647208Scael.Ao Pa sys/time.h Ac
4720139Smckusickas:
4847208Scael.Pp
4947208Scael.Bd -literal
5020139Smckusickstruct timeval {
5127648Slepreau	long	tv_sec;		/* seconds since Jan. 1, 1970 */
5247208Scael	long	tv_usec;	/* and microseconds */
5320139Smckusick};
5447208Scael
5520139Smckusickstruct timezone {
5647208Scael	int	tz_minuteswest; /* of Greenwich */
5720139Smckusick	int	tz_dsttime;	/* type of dst correction to apply */
5820139Smckusick};
5947208Scael.Ed
6047208Scael.Pp
6120139SmckusickThe
6247208Scael.Fa timezone
6320139Smckusickstructure indicates the local time zone
6420139Smckusick(measured in minutes of time westward from Greenwich),
6520139Smckusickand a flag that, if nonzero, indicates that
6620139SmckusickDaylight Saving time applies locally during
6720139Smckusickthe appropriate part of the year.
6847208Scael.Pp
6927648SlepreauOnly the super-user may set the time of day or time zone.
70*69706SmckusickIf the system is running in secure mode (see
71*69706Smckusick.Xr init 8 ),
72*69706Smckusickthe time may only be advanced.
73*69706SmckusickThis limitation is imposed to prevent a malicious super-user
74*69706Smckusickfrom setting arbitrary time stamps on files.
75*69706SmckusickThe system time can still be adjusted backwards using the
76*69706Smckusick.Xr adjtime 2
77*69706Smckusicksystem call even when the system is secure.
7847208Scael.Sh RETURN
7920139SmckusickA 0 return value indicates that the call succeeded.
8047208ScaelA -1 return value indicates an error occurred, and in this
8147208Scaelcase an error code is stored into the global variable
8247208Scael.Va errno .
8347208Scael.Sh ERRORS
8447208ScaelThe following error codes may be set in
8547208Scael.Va errno :
8647208Scael.Bl -tag -width [EFAULT]
8747208Scael.It Bq Er EFAULT
8820139SmckusickAn argument address referenced invalid memory.
8947208Scael.It Bq Er EPERM
9020139SmckusickA user other than the super-user attempted to set the time.
9147208Scael.El
9247208Scael.Sh SEE ALSO
9347208Scael.Xr date 1 ,
9447208Scael.Xr adjtime 2 ,
9547208Scael.Xr ctime 3 ,
9647208Scael.Xr timed 8
9747208Scael.Sh HISTORY
9847208ScaelThe
9947208Scael.Nm
10047208Scaelfunction call appeared in
10147208Scael.Bx 4.2 .
102