struct timex and Linux adjtimex()

Poul-Henning Kamp phk at phk.freebsd.dk
Thu Dec 3 20:15:31 UTC 2020


--------
Konstantin Belousov writes:

>
>               The  value  of  buf.time  is  the sum of its two fields, but the
>               field buf.time.tv_usec must always be nonnegative.  The  follow‐
>               ing  example  shows  how  to normalize a timeval with nanosecond
>               resolution.
>
>                    while (buf.time.tv_usec < 0) {
>                        buf.time.tv_sec  -= 1;
>                        buf.time.tv_usec += 1000000000;
>                    }
>
> I do not quite understand the context and internal meaning of the second
> paragraph, though.  Kernel should not allow negative tv_usec as the input
> parameter, right ?

Correct.

Minus 10 nanoseconds should be expressed as { .tv_sec = -1; .tv_nsec = 999999990; }

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.


More information about the freebsd-arch mailing list