The time_t
data type used to represent simple times has a
resolution of only one second. Some applications need more precision.
So, the GNU C library also contains functions which are capable of representing calendar times to a higher resolution than one second. The functions and the associated data types described in this section are declared in `sys/time.h'.
struct timezone
structure is used to hold minimal information
about the local time zone. It has the following members:
int tz_minuteswest
int tz_dsttime
The struct timezone
type is obsolete and should never be used.
Instead, use the facilities described in section Functions and Variables for Time Zones.
gettimeofday
function returns the current calendar time as
the elapsed time since the epoch in the struct timeval
structure
indicated by tp. (see section Elapsed Time for a description of
struct timespec
). Information about the time zone is returned in
the structure pointed at tzp. If the tzp argument is a null
pointer, time zone information is ignored.
The return value is 0
on success and -1
on failure. The
following errno
error condition is defined for this function:
ENOSYS
struct timezone
to represent time zone
information; that is an obsolete feature of 4.3 BSD.
Instead, use the facilities described in section Functions and Variables for Time Zones.
settimeofday
function sets the current calendar time in the
system clock according to the arguments. As for gettimeofday
,
the calendar time is represented as the elapsed time since the epoch.
As for gettimeofday
, time zone information is ignored if
tzp is a null pointer.
You must be a privileged user in order to use settimeofday
.
Some kernels automatically set the system clock from some source such as
a hardware clock when they start up. Others, including Linux, place the
system clock in an "invalid" state (in which attempts to read the clock
fail). A call of stime
removes the system clock from an invalid
state, and system startup scripts typically run a program that calls
stime
.
settimeofday
causes a sudden jump forwards or backwards, which
can cause a variety of problems in a system. Use adjtime
(below)
to make a smooth transition from one time to another by temporarily
speeding up or slowing down the clock.
With a Linux kernel, adjtimex
does the same thing and can also
make permanent changes to the speed of the system clock so it doesn't
need to be corrected as often.
The return value is 0
on success and -1
on failure. The
following errno
error conditions are defined for this function:
EPERM
ENOSYS
The delta argument specifies a relative adjustment to be made to the clock time. If negative, the system clock is slowed down for a while until it has lost this much elapsed time. If positive, the system clock is speeded up for a while.
If the olddelta argument is not a null pointer, the adjtime
function returns information about any previous time adjustment that
has not yet completed.
This function is typically used to synchronize the clocks of computers in a local network. You must be a privileged user to use it.
With a Linux kernel, you can use the adjtimex
function to
permanently change the clock speed.
The return value is 0
on success and -1
on failure. The
following errno
error condition is defined for this function:
EPERM
Portability Note: The gettimeofday
, settimeofday
,
and adjtime
functions are derived from BSD.
Symbols for the following function are declared in `sys/timex.h'.
adjtimex
is functionally identical to ntp_adjtime
.
See section High Accuracy Clock.
This function is present only with a Linux kernel.
Go to the first, previous, next, last section, table of contents.