From: Dmitry V. Levin Date: Fri, 26 Dec 2014 23:55:38 +0000 (+0000) Subject: Cleanup UTIME_NOW/UTIME_OMIT decoding X-Git-Tag: v4.10~269 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ee21a5ba35d7ea68830f7d51b4bfb8e10c060eb9;p=strace Cleanup UTIME_NOW/UTIME_OMIT decoding Move the code that's present in two copies from sprinttv() to a new helper function. * time.c (do_sprinttv): New function. (sprinttv): Use it. --- diff --git a/time.c b/time.c index 68efc803..31f0846e 100644 --- a/time.c +++ b/time.c @@ -66,11 +66,24 @@ printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special) tprints(buf); } +static char * +do_sprinttv(char *buf, const unsigned long sec, const unsigned long usec, + const int special) +{ + if (special) { + switch (usec) { + case UTIME_NOW: + return stpcpy(buf, "UTIME_NOW"); + case UTIME_OMIT: + return stpcpy(buf, "UTIME_OMIT"); + } + } + return buf + sprintf(buf, "{%lu, %lu}", sec, usec); +} + char * sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special) { - int rc; - if (addr == 0) return stpcpy(buf, "NULL"); @@ -85,32 +98,13 @@ sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int spec { struct timeval32 tv; - rc = umove(tcp, addr, &tv); - if (rc >= 0) { - if (special) { - if (tv.tv_usec == UTIME_NOW) - return stpcpy(buf, "UTIME_NOW"); - if (tv.tv_usec == UTIME_OMIT) - return stpcpy(buf, "UTIME_OMIT"); - } - return buf + sprintf(buf, "{%u, %u}", - tv.tv_sec, tv.tv_usec); - } + if (umove(tcp, addr, &tv) >= 0) + return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special); } else { struct timeval tv; - rc = umove(tcp, addr, &tv); - if (rc >= 0) { - if (special) { - if (tv.tv_usec == UTIME_NOW) - return stpcpy(buf, "UTIME_NOW"); - if (tv.tv_usec == UTIME_OMIT) - return stpcpy(buf, "UTIME_OMIT"); - } - return buf + sprintf(buf, "{%lu, %lu}", - (unsigned long) tv.tv_sec, - (unsigned long) tv.tv_usec); - } + if (umove(tcp, addr, &tv) >= 0) + return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special); } return stpcpy(buf, "{...}");