On Wed, May 16, 2012 at 05:24:10PM +0200, Nikola Pajkovsky wrote:
Vitezslav Samel <vitezslav(a)samel.cz> writes:
> This one computes difference in milliseconds between
> two structs timeval.
>
> Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
> ---
> src/iptraf-ng-compat.h | 27 +++++++++++++++++++++++++++
> 1 files changed, 27 insertions(+), 0 deletions(-)
>
> diff --git a/src/iptraf-ng-compat.h b/src/iptraf-ng-compat.h
> index b2cc0ac..ac10127 100644
> --- a/src/iptraf-ng-compat.h
> +++ b/src/iptraf-ng-compat.h
> @@ -112,4 +112,31 @@ static inline char *skip_whitespace(char *str)
> return str;
> }
I don't see any point to have two functions. See
At start I wanted to have function which doesn't check validity of
pointers (when using f(&a, &b) there's no need to check), but later
I decided that these checks aren't that heavy and left both functions
in the file.
I'll kill that function without tests.
Vita
> +static inline unsigned long __timeval_diff_msec(const struct
timeval *end,
> + const struct timeval *start)
> +{
if (!start || !end)
return 0UL;
> + signed long secs = end->tv_sec - start->tv_sec;
> + signed long usecs = end->tv_usec - start->tv_usec;
> +
> + if(usecs < 0) {
> + usecs = 1000000 - usecs;
> + secs -= 1;
> + }
> + if(secs >= 0)
> + return secs * 1000UL + usecs / 1000UL;
> + else
> + return 0UL;
> +}
and now you don't have to use __timeval... naming