Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Jun 1997 20:09:09 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        joerg_wunsch@uriah.heep.sax.de, msmith@atrad.adelaide.edu.au
Cc:        hackers@FreeBSD.ORG
Subject:   Re: libedit, etc. (CVS issues)
Message-ID:  <199706251009.UAA30436@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>Dang; I was too quick.  Ok, rule of thumb is "once changed from the
>original import, should have $Id$", correct?

No, it is
1. Once changed from the vendor branch, should have $Id$".

More important rules:

2. Don't gratuitously change from the vendor branch.
3. Don't change just to add $Id$".

>I'll backtrack and catch the ones I've just committed.  

Breaks rule 3.

>Does anyone know what the NetBSD function "timersub()" is supposed to do?

Yes :-).  It is supposed to pollute <sys/time.h> with a kernel interface.
It is usually a poor way to subtract timevals in userland.  ftp/util.c
gives two examples of how to misuse it, of the form:

	double delta;
	struct timeval start, finish, td;
	...
	timersub(&finish, &start, &td);
	delta = td.tv_sec + tv.tv_usec / 1000000.0;

This can be done more efficiently and naturally directly:

	...
	delta = finish.tv_sec - start.tv_sec +
		(finish.tv_usec - start.tv_usec) / 1000000.0;

ftp/util.c gives one example of how to use it, of the form:

	struct timeval start, finish, td, start1, finish1, td1;
	double delta;
	...
	if (something) {
		timersub(&finish1, &start1, td1);
		/* BUG (should use timeradd() here): */
		start.tv_sec += start1.tv_sec;
		start.tv_usec += start1.tv_usec;
	}
	/*
	 * BUG: timersub() only works on valid timevals, but `start'
	 * may be invalid here (its tv_usec may be > 1000000.  However,
	 * the floating point calculation fixes up the value.
	 */
	timevalsub(&finish, &start, &td);
	delta = td.tv_sec + tv.tv_usec / 1000000.0;
	...
	/* Something else using td1. */

This example could be changed to use a floating point td1, but that would
be slower on machines with slow floating point.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199706251009.UAA30436>