]> granicus.if.org Git - strace/commitdiff
Cleanup UTIME_NOW/UTIME_OMIT decoding
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 26 Dec 2014 23:55:38 +0000 (23:55 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 27 Dec 2014 00:39:21 +0000 (00:39 +0000)
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.

time.c

diff --git a/time.c b/time.c
index 68efc803a898e177b9974dbfe824d52833856671..31f0846ee316c9fd486ac01ef30ef682700b800f 100644 (file)
--- 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, "{...}");