tzfile.5, tzselect.8: sync from tzdb upstream
[man-pages.git] / man3 / adjtime.3
blob1c4a071ce7888f069ba3175e3d930b197b192afc
1 '\" t
2 .\" Copyright (c) 2006 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH adjtime 3 (date) "Linux man-pages (unreleased)"
7 .SH NAME
8 adjtime \- correct the time to synchronize the system clock
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ", " \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <sys/time.h>
15 .PP
16 .BI "int adjtime(const struct timeval *" delta ", struct timeval *" olddelta );
17 .fi
18 .PP
19 .RS -4
20 Feature Test Macro Requirements for glibc (see
21 .BR feature_test_macros (7)):
22 .RE
23 .PP
24 .BR adjtime ():
25 .nf
26     Since glibc 2.19:
27         _DEFAULT_SOURCE
28     glibc 2.19 and earlier:
29         _BSD_SOURCE
30 .fi
31 .SH DESCRIPTION
32 The
33 .BR adjtime ()
34 function gradually adjusts the system clock (as returned by
35 .BR gettimeofday (2)).
36 The amount of time by which the clock is to be adjusted is specified
37 in the structure pointed to by
38 .IR delta .
39 This structure has the following form:
40 .PP
41 .in +4n
42 .EX
43 struct timeval {
44     time_t      tv_sec;     /* seconds */
45     suseconds_t tv_usec;    /* microseconds */
47 .EE
48 .in
49 .PP
50 If the adjustment in
51 .I delta
52 is positive, then the system clock is speeded up by some
53 small percentage (i.e., by adding a small
54 amount of time to the clock value in each second) until the adjustment
55 has been completed.
56 If the adjustment in
57 .I delta
58 is negative, then the clock is slowed down in a similar fashion.
59 .PP
60 If a clock adjustment from an earlier
61 .BR adjtime ()
62 call is already in progress
63 at the time of a later
64 .BR adjtime ()
65 call, and
66 .I delta
67 is not NULL for the later call, then the earlier adjustment is stopped,
68 but any already completed part of that adjustment is not undone.
69 .PP
71 .I olddelta
72 is not NULL, then the buffer that it points to is used to return
73 the amount of time remaining from any previous adjustment that
74 has not yet been completed.
75 .SH RETURN VALUE
76 On success,
77 .BR adjtime ()
78 returns 0.
79 On failure, \-1 is returned, and
80 .I errno
81 is set to indicate the error.
82 .SH ERRORS
83 .TP
84 .B EINVAL
85 The adjustment in
86 .I delta
87 is outside the permitted range.
88 .TP
89 .B EPERM
90 The caller does not have sufficient privilege to adjust the time.
91 Under Linux, the
92 .B CAP_SYS_TIME
93 capability is required.
94 .SH ATTRIBUTES
95 For an explanation of the terms used in this section, see
96 .BR attributes (7).
97 .ad l
98 .nh
99 .TS
100 allbox;
101 lbx lb lb
102 l l l.
103 Interface       Attribute       Value
105 .BR adjtime ()
106 T}      Thread safety   MT-Safe
110 .sp 1
111 .SH STANDARDS
112 4.3BSD, System V.
113 .SH NOTES
114 The adjustment that
115 .BR adjtime ()
116 makes to the clock is carried out in such a manner that the clock
117 is always monotonically increasing.
118 Using
119 .BR adjtime ()
120 to adjust the time prevents the problems that can be caused for certain
121 applications (e.g.,
122 .BR make (1))
123 by abrupt positive or negative jumps in the system time.
125 .BR adjtime ()
126 is intended to be used to make small adjustments to the system time.
127 Most systems impose a limit on the adjustment that can be specified in
128 .IR delta .
129 In the glibc implementation,
130 .I delta
131 must be less than or equal to (INT_MAX / 1000000 \- 2)
132 and greater than or equal to (INT_MIN / 1000000 + 2)
133 (respectively 2145 and \-2145 seconds on i386).
134 .SH BUGS
135 A longstanding bug
136 .\" http://sourceware.org/bugzilla/show_bug?id=2449
137 .\" http://bugzilla.kernel.org/show_bug.cgi?id=6761
138 meant that if
139 .I delta
140 was specified as NULL,
141 no valid information about the outstanding clock adjustment was returned in
142 .IR olddelta .
143 (In this circumstance,
144 .BR adjtime ()
145 should return the outstanding clock adjustment, without changing it.)
146 This bug is fixed
147 .\" Thanks to the new adjtimex() ADJ_OFFSET_SS_READ flag
148 on systems with glibc 2.8 or later and
149 Linux kernel 2.6.26 or later.
150 .SH SEE ALSO
151 .BR adjtimex (2),
152 .BR gettimeofday (2),
153 .BR time (7)