gettimeofday(2) — System Calls
OSF
NAME
gettimeofday, settimeofday, ftime − Gets and sets date and time
LIBRARY
Standard C Library (libc.a)
ftime() call: Berkeley Compatibility Library (libbsd.a)
SYNOPSIS
#include <sys/time.h> int gettimeofday (
struct timeval ∗tp,
struct timezone ∗tzp ); int settimeofday (
struct timeval ∗tp,
struct timezone ∗tzp ); #include <sys/time.h>
#include <sys/timeb.h> int ftime (
struct timeb ∗tp );
PARAMETERS
tpPoints to a timeval structure, defined in the sys/time.h file.
tzpPoints to a timezone structure, defined in the sys/time.h file.
DESCRIPTION
The gettimeofday() and settimeofday() functions get and set the system’s notion of the current time and time zone. The time is expressed in seconds and microseconds since midnight (0 hour), January 1, 1970. The resolution of the system clock is hardware dependent, and the time may be updated continuously or in ”ticks.” If the tzp parameter is 0 (zero), the time zone information will not be returned or set.
The tp parameter returns a pointer to a timeval structure which contains the time since the epoch began in seconds (up to 1000 milliseconds of a more precise interval), the local time zone (measured in minutes westward from Coordinated Universal Time), and a flag that, if nonzero, indicates that daylight saving time applies.
The timezone structure indicates the local time zone (measured in minutes of time westward from Greenwich), and a flag that, if nonzero, indicates that daylight saving time applies locally during the appropriate part of the year.
In addition to the difference in timer granularity, the timezone structure distinguishes these calls from the OSF Application Environment Specification getclock and setclock calls, which deal strictly with Coordinated Universal Time.
NOTES
A process must have superuser privilege to set the system’s time.
The gettimeofday() and settimeofday() functions are supported for compatibility with BSD programs. They support a process-local time zone parameter in addition to the system-wide time and date.
The ftime() function is included for compatibility with older BSD programs. Its function has been made obsolete by the gettimeofday() function.
RETURN VALUES
Upon successful completion, a value of 0 (zero) is returned. Otherwise, -1 is returned and errno is set to indicate the error.
ERRORS
If the gettimeofday() or settimeofday() function fails, errno may be set the following value:
[EFAULT]A parameter points to an invalid address.
[EPERM]The process’s effective user ID does not have superuser privilege.
RELATED INFORMATION
Functions: adjtime(2), ctime(3), gettimer(3), strftime(3)
Commands: date(1)