Skip to content

Commit

Permalink
tv_usec must always be positive
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fb-martin committed Jan 8, 2023
1 parent 02618ee commit 7717d69
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hc_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ static void hc_clock_adjust (time_t drift) {

delta.tv_sec = (drift / 1000);
delta.tv_usec = (drift % 1000) * 1000;
if (delta.tv_usec < 0) {
// Per the GNU libc documentation, tv_usec must be positive, and
// microsecond time = (tv_sec * 1000000) + tv_usec.
delta.tv_sec -= 1;
delta.tv_usec += 1000000;
}
if (adjtime (&delta, NULL) != 0) {
printf ("adjtime() error %d\n", errno);
}
Expand Down

0 comments on commit 7717d69

Please sign in to comment.