diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-07-19 23:28:12 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-07-19 23:28:12 +0000 |
commit | 2f302486800b0a216e245e8fe243988e99d1cadc (patch) | |
tree | 5b960fce5e253942404859ea45f63c509d960f33 /include | |
parent | c37a8a42b203bde0af14dc15b38a383ae6fbdb27 (diff) |
restore proper difference calculation (bug #4746)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6166 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include')
-rwxr-xr-x | include/asterisk/time.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/include/asterisk/time.h b/include/asterisk/time.h index a10636a69..dbdfb446a 100755 --- a/include/asterisk/time.h +++ b/include/asterisk/time.h @@ -32,7 +32,13 @@ typedef typeof(tv.tv_usec) ast_suseconds_t; AST_INLINE_API( int ast_tvdiff_ms(struct timeval end, struct timeval start), { - return ((end.tv_sec - start.tv_sec) * 1000) + ((end.tv_usec - start.tv_usec) / 1000); + /* the offset by 1,000,000 below is intentional... + it avoids differences in the way that division + is handled for positive and negative numbers, by ensuring + that the divisor is always positive + */ + return ((end.tv_sec - start.tv_sec) * 1000) + + (((1000000 + end.tv_usec - start.tv_usec) / 1000) - 1000); } ) |