man-pages/man3/adjtime.3.html
2021-03-31 01:06:50 +01:00

241 lines
5.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of ADJTIME</TITLE>
</HEAD><BODY>
<H1>ADJTIME</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
adjtime - correct the time to synchronize the system clock
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/sys/time.h">sys/time.h</A>&gt;</B>
<B>int adjtime(const struct timeval *</B><I>delta</I><B>, struct timeval *</B><I>olddelta</I><B>);</B>
</PRE>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>adjtime</B>():
<BR>&nbsp;&nbsp;&nbsp;&nbsp;Since&nbsp;glibc&nbsp;2.19:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_DEFAULT_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;Glibc&nbsp;2.19&nbsp;and&nbsp;earlier:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_BSD_SOURCE
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>adjtime</B>()
function gradually adjusts the system clock (as returned by
<B><A HREF="/cgi-bin/man/man2html?2+gettimeofday">gettimeofday</A></B>(2)).
The amount of time by which the clock is to be adjusted is specified
in the structure pointed to by
<I>delta</I>.
This structure has the following form:
<P>
struct timeval {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;time_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tv_sec;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;seconds&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;suseconds_t&nbsp;tv_usec;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;microseconds&nbsp;*/
};
<P>
If the adjustment in
<I>delta</I>
is positive, then the system clock is speeded up by some
small percentage (i.e., by adding a small
amount of time to the clock value in each second) until the adjustment
has been completed.
If the adjustment in
<I>delta</I>
is negative, then the clock is slowed down in a similar fashion.
<P>
If a clock adjustment from an earlier
<B>adjtime</B>()
call is already in progress
at the time of a later
<B>adjtime</B>()
call, and
<I>delta</I>
is not NULL for the later call, then the earlier adjustment is stopped,
but any already completed part of that adjustment is not undone.
<P>
If
<I>olddelta</I>
is not NULL, then the buffer that it points to is used to return
the amount of time remaining from any previous adjustment that
has not yet been completed.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success,
<B>adjtime</B>()
returns 0.
On failure, -1 is returned, and
<I>errno</I>
is set to indicate the error.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="1"><B>EINVAL</B>
<DD>
The adjustment in
<I>delta</I>
is outside the permitted range.
<DT id="2"><B>EPERM</B>
<DD>
The caller does not have sufficient privilege to adjust the time.
Under Linux, the
<B>CAP_SYS_TIME</B>
capability is required.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>adjtime</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
4.3BSD, System V.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
The adjustment that
<B>adjtime</B>()
makes to the clock is carried out in such a manner that the clock
is always monotonically increasing.
Using
<B>adjtime</B>()
to adjust the time prevents the problems that can be caused for certain
applications (e.g.,
<B><A HREF="/cgi-bin/man/man2html?1+make">make</A></B>(1))
by abrupt positive or negative jumps in the system time.
<P>
<B>adjtime</B>()
is intended to be used to make small adjustments to the system time.
Most systems impose a limit on the adjustment that can be specified in
<I>delta</I>.
In the glibc implementation,
<I>delta</I>
must be less than or equal to (INT_MAX / 1000000 - 2)
and greater than or equal to (INT_MIN / 1000000 + 2)
(respectively 2145 and -2145 seconds on i386).
<A NAME="lbAJ">&nbsp;</A>
<H2>BUGS</H2>
A longstanding bug
meant that if
<I>delta</I>
was specified as NULL,
no valid information about the outstanding clock adjustment was returned in
<I>olddelta</I>.
(In this circumstance,
<B>adjtime</B>()
should return the outstanding clock adjustment, without changing it.)
This bug is fixed
on systems with glibc 2.8 or later and
Linux kernel 2.6.26 or later.
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+adjtimex">adjtimex</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+gettimeofday">gettimeofday</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?7+time">time</A></B>(7)
<A NAME="lbAL">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="3"><A HREF="#lbAB">NAME</A><DD>
<DT id="4"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="5"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="6"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="7"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="8"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="9"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="10"><A HREF="#lbAI">NOTES</A><DD>
<DT id="11"><A HREF="#lbAJ">BUGS</A><DD>
<DT id="12"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="13"><A HREF="#lbAL">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:35 GMT, March 31, 2021
</BODY>
</HTML>