From 7e4cb006252fd33dbfa9f6ef025acc6e9c28a29e Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Thu, 9 May 2019 22:03:30 +0000 Subject: [PATCH] print_timespec.c: introduce helper macros and functions They are going to be used to implement printers of other timespec flavours, e.g. kernel_timespec32_t and kernel_timespec64_t. * print_timespec.c (TIMESPEC_TO_SEC_NSEC): New macro. (print_timespec_t_utime, sprint_timespec): Use it. (print_sec_nsec): New function. (print_timespec_t): Use it. --- print_timespec.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/print_timespec.c b/print_timespec.c index 97c6bc30..18100978 100644 --- a/print_timespec.c +++ b/print_timespec.c @@ -23,13 +23,21 @@ typedef struct timespec timespec_t; # define UTIME_OMIT ((1l << 30) - 2l) #endif +#define TIMESPEC_TO_SEC_NSEC(t_) \ + ((long long) (t_)->tv_sec), zero_extend_signed_to_ull((t_)->tv_nsec) + static const char timespec_fmt[] = "{tv_sec=%lld, tv_nsec=%llu}"; +static void +print_sec_nsec(long long sec, unsigned long long nsec) +{ + tprintf(timespec_fmt, sec, nsec); +} + static void print_timespec_t(const timespec_t *t) { - tprintf(timespec_fmt, (long long) t->tv_sec, - zero_extend_signed_to_ull(t->tv_nsec)); + print_sec_nsec(TIMESPEC_TO_SEC_NSEC(t)); } static void @@ -49,8 +57,7 @@ print_timespec_t_utime(const timespec_t *t) break; default: print_timespec_t(t); - tprints_comment(sprinttime_nsec(t->tv_sec, - zero_extend_signed_to_ull(t->tv_nsec))); + tprints_comment(sprinttime_nsec(TIMESPEC_TO_SEC_NSEC(t))); break; } } @@ -115,9 +122,7 @@ MPERS_PRINTER_DECL(const char *, sprint_timespec, umove(tcp, addr, &t)) { xsprintf(buf, "%#" PRI_klx, addr); } else { - xsprintf(buf, timespec_fmt, - (long long) t.tv_sec, - zero_extend_signed_to_ull(t.tv_nsec)); + xsprintf(buf, timespec_fmt, TIMESPEC_TO_SEC_NSEC(&t)); } return buf; -- 2.40.0