diff options
author | Björn Jacke <bj@sernet.de> | 2010-08-30 17:56:37 +0200 |
---|---|---|
committer | Björn Jacke <bj@sernet.de> | 2010-08-31 10:26:23 +0200 |
commit | 73ad77f20a136b74a4ae381c8b97acf248d3c8fe (patch) | |
tree | 854ee7e4f486c1552cae502fea62c6365dc0ff7d /lib | |
parent | 0ca6a73d011abd20d8a9256f6dfe3517bd1a27ef (diff) | |
download | samba-73ad77f20a136b74a4ae381c8b97acf248d3c8fe.tar.gz samba-73ad77f20a136b74a4ae381c8b97acf248d3c8fe.tar.bz2 samba-73ad77f20a136b74a4ae381c8b97acf248d3c8fe.zip |
lib/util: add nsec_time_diff to calulate diffs from timespecs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/time.c | 9 | ||||
-rw-r--r-- | lib/util/time.h | 5 |
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/util/time.c b/lib/util/time.c index 5557346b9b..5ecf93cb77 100644 --- a/lib/util/time.c +++ b/lib/util/time.c @@ -409,6 +409,15 @@ _PUBLIC_ int64_t usec_time_diff(const struct timeval *tv1, const struct timeval return (sec_diff * 1000000) + (int64_t)(tv1->tv_usec - tv2->tv_usec); } +/** + return (tp1 - tp2) in microseconds +*/ +_PUBLIC_ int64_t nsec_time_diff(const struct timespec *tp1, const struct timespec *tp2) +{ + int64_t sec_diff = tp1->tv_sec - tp2->tv_sec; + return (sec_diff * 1000000000) + (int64_t)(tp1->tv_nsec - tp2->tv_nsec); +} + /** return a zero timeval diff --git a/lib/util/time.h b/lib/util/time.h index 90890cdbc8..720a262b29 100644 --- a/lib/util/time.h +++ b/lib/util/time.h @@ -149,6 +149,11 @@ _PUBLIC_ NTTIME nttime_from_string(const char *s); _PUBLIC_ int64_t usec_time_diff(const struct timeval *tv1, const struct timeval *tv2); /** + return (tp1 - tp2) in nanoseconds +*/ +_PUBLIC_ int64_t nsec_time_diff(const struct timespec *tp1, const struct timespec *tp2); + +/** return a zero timeval */ _PUBLIC_ struct timeval timeval_zero(void); |