Debian Codegraph @

upstream/debian-unstable/man3/adjtime.3

raw
1 '\" t
2 .\" Copyright 2006, Michael Kerrisk <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH adjtime 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 adjtime \- correct the time to synchronize the system clock
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <sys/time.h>
16 .P
17 .BI "int adjtime(const struct timeval *" delta ", struct timeval *" olddelta );
18 .fi
19 .P
20 .RS -4
21 Feature Test Macro Requirements for glibc (see
22 .BR feature_test_macros (7)):
23 .RE
24 .P
25 .BR adjtime ():
26 .nf
27 Since glibc 2.19:
28 _DEFAULT_SOURCE
29 glibc 2.19 and earlier:
30 _BSD_SOURCE
31 .fi
32 .SH DESCRIPTION
33 The
34 .BR adjtime ()
35 function gradually adjusts the system clock (as returned by
36 .BR gettimeofday (2)).
37 The amount of time by which the clock is to be adjusted is specified
38 in the structure pointed to by
39 .IR delta .
40 This structure has the following form:
41 .P
42 .in +4n
43 .EX
44 struct timeval {
45 time_t tv_sec; /* seconds */
46 suseconds_t tv_usec; /* microseconds */
47 };
48 .EE
49 .in
50 .P
51 If the adjustment in
52 .I delta
53 is positive, then the system clock is speeded up by some
54 small percentage (i.e., by adding a small
55 amount of time to the clock value in each second) until the adjustment
56 has been completed.
57 If the adjustment in
58 .I delta
59 is negative, then the clock is slowed down in a similar fashion.
60 .P
61 If a clock adjustment from an earlier
62 .BR adjtime ()
63 call is already in progress
64 at the time of a later
65 .BR adjtime ()
66 call, and
67 .I delta
68 is not NULL for the later call, then the earlier adjustment is stopped,
69 but any already completed part of that adjustment is not undone.
70 .P
71 If
72 .I olddelta
73 is not NULL, then the buffer that it points to is used to return
74 the amount of time remaining from any previous adjustment that
75 has not yet been completed.
76 .SH RETURN VALUE
77 On success,
78 .BR adjtime ()
79 returns 0.
80 On failure, \-1 is returned, and
81 .I errno
82 is set to indicate the error.
83 .SH ERRORS
84 .TP
85 .B EINVAL
86 The adjustment in
87 .I delta
88 is outside the permitted range.
89 .TP
90 .B EPERM
91 The caller does not have sufficient privilege to adjust the time.
92 Under Linux, the
93 .B CAP_SYS_TIME
94 capability is required.
95 .SH ATTRIBUTES
96 For an explanation of the terms used in this section, see
97 .BR attributes (7).
98 .TS
99 allbox;
100 lbx lb lb
101 l l l.
102 Interface Attribute Value
103 T{
104 .na
105 .nh
106 .BR adjtime ()
107 T} Thread safety MT-Safe
108 .TE
109 .SH STANDARDS
110 None.
111 .SH HISTORY
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 could be caused for certain
121 applications (e.g.,
122 .BR make (1))
123 by abrupt positive or negative jumps in the system time.
124 .P
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)