From 60c9d9f701bf7bca91a468b41a7373a2e7290430 Mon Sep 17 00:00:00 2001 From: brarcher Date: Tue, 17 Dec 2013 22:12:12 +0000 Subject: [PATCH] Add #define for US_PER_SEC, to avoid magic numbers git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@890 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- src/check_impl.h | 4 +++- src/check_log.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/check_impl.h b/src/check_impl.h index ec8bda2..1f59ee1 100644 --- a/src/check_impl.h +++ b/src/check_impl.h @@ -26,9 +26,11 @@ Include stdio.h, time.h, & list.h before this header */ +#define US_PER_SEC 1000000 + /** calculate the difference in useconds out of two "struct timespec"s */ #define DIFF_IN_USEC(begin, end) \ - ( (((end).tv_sec - (begin).tv_sec) * 1000000) + \ + ( (((end).tv_sec - (begin).tv_sec) * US_PER_SEC) + \ ((end).tv_nsec/1000) - ((begin).tv_nsec/1000) ) typedef struct TF { diff --git a/src/check_log.c b/src/check_log.c index 5c02f47..49eb0d8 100644 --- a/src/check_log.c +++ b/src/check_log.c @@ -282,7 +282,7 @@ void xml_lfun (SRunner *sr CK_ATTRIBUTE_UNUSED, FILE *file, enum print_output pr clock_gettime(check_get_clockid(), &ts_end); duration = DIFF_IN_USEC(ts_start, ts_end); fprintf(file, " %u.%06u\n", - duration / 1000000, duration % 1000000); + duration / US_PER_SEC, duration % US_PER_SEC); fprintf(file, "\n"); } break; -- 2.40.0