[PATCH] lib/util: fix timespec normalization

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Jan 17 10:58:16 UTC 2019


On Thu, Jan 17, 2019 at 11:40:48AM +0100, Philipp Gesang via samba-technical wrote:
> +
> +/****************************************************************************
> + Deal with nanoseconds overflow.
> +****************************************************************************/
> +
> +void normalize_timespec(struct timespec *ts)
> +{
> +	while (ts->tv_nsec >= NSEC_PER_SEC) {
> +		++ts->tv_sec;
> +		ts->tv_nsec -= NSEC_PER_SEC;
> +	}
> +	while (ts->tv_nsec < 0) {
> +		--ts->tv_sec;
> +		ts->tv_nsec += NSEC_PER_SEC;
> +	}
> +}

This looks a bit inefficient to be honest. Shouldn't that be faster
doing some modulo-magic?

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: 0551-370000-0, mailto:kontakt at sernet.de
Gesch.F.: Dr. Johannes Loxen und Reinhild Jung
AG Göttingen: HR-B 2816 - http://www.sernet.de



More information about the samba-technical mailing list