Skip to content

Revise work with struct timeval to not rely on signedness of tv_sec/tv_usec #1937

@jimklimov

Description

@jimklimov

The https://www.gnu.org/software/libc/manual/html_node/Calculating-Elapsed-Time.html document suggests that there may be systems which account struct timeval fields tv_sec/tv_usec as unsigned values, so under-flows are possible when subtracting times from each other. The sample method from that document was adapted as difftimeval() in #1936; possibly the original method is also desirable to replace our loops currently similar to this:

		tv.tv_usec -= difftimeval(now, start);
		while (tv.tv_usec < 0) {
			tv.tv_sec--;
			tv.tv_usec = 1000000 + tv.tv_usec;  // Note it is negative
		}

See also: #1938 / #3321

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-timeIssues and PRs about C/C++ methods, headers and data types dealing with timeportabilityWe want NUT to build and run everywhere possible

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions