]> granicus.if.org Git - strace/commitdiff
Print timeval pair as an array of timeval entries
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sun, 27 Nov 2016 20:24:12 +0000 (23:24 +0300)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 28 Nov 2016 04:38:42 +0000 (04:38 +0000)
* print_timeval.c (print_timeval_item): New function.
(print_timeval_pair): Use it as a print_function in print_array call.
* tests/futimesat.c (main): Update to test new behaviour.
* tests/utimes.c (main): Likewise.

print_timeval.c
tests/futimesat.c
tests/utimes.c

index 7722062195d645ce4730796fb66606b136dbab22..1b4807c47f8f4d7067cdac3986b04838c44bed81 100644 (file)
@@ -57,19 +57,23 @@ MPERS_PRINTER_DECL(void, print_timeval,
        print_timeval_t(&t);
 }
 
+static bool
+print_timeval_item(struct tcb *tcp, void *elem_buf, size_t size, void *data)
+{
+       timeval_t *t = elem_buf;
+
+       print_timeval_t(t);
+
+       return true;
+}
+
 MPERS_PRINTER_DECL(void, print_timeval_pair,
                   struct tcb *tcp, const long addr)
 {
-       timeval_t t[2];
-
-       if (umove_or_printaddr(tcp, addr, &t))
-               return;
+       timeval_t t;
 
-       tprints("[");
-       print_timeval_t(&t[0]);
-       tprints(", ");
-       print_timeval_t(&t[1]);
-       tprints("]");
+       print_array(tcp, addr, 2, &t, sizeof(t), umoven_or_printaddr,
+                   print_timeval_item, NULL);
 }
 
 MPERS_PRINTER_DECL(const char *, sprint_timeval,
index 3e04bd3cd22592057f1010eef6a3fbc351bfee03..c3566291265928690f19f9fdff49c7080c7da66a 100644 (file)
@@ -55,15 +55,21 @@ main(void)
        struct timeval *const ts = tail_alloc(sizeof(*ts) * 2);
        dirfd = (unsigned long) 0xdeadbeefffffffffULL;
 
-       rc = syscall(__NR_futimesat, dirfd, 0, ts + 1);
-       printf("futimesat(%d, NULL, %p) = %ld %s (%m)\n",
-              (int) dirfd, ts + 1, rc, errno2name());
-
        ts[0].tv_sec = tv.tv_sec;
        ts[0].tv_usec = tv.tv_usec;
        ts[1].tv_sec = tv.tv_sec - 1;
        ts[1].tv_usec = tv.tv_usec + 1;
 
+       rc = syscall(__NR_futimesat, dirfd, 0, ts + 2);
+       printf("futimesat(%d, NULL, %p) = %ld %s (%m)\n",
+              (int) dirfd, ts + 2, rc, errno2name());
+
+       rc = syscall(__NR_futimesat, dirfd, 0, ts + 1);
+       printf("futimesat(%d, NULL, [{tv_sec=%jd, tv_usec=%jd}, %p]) = "
+              "%ld %s (%m)\n", (int) dirfd,
+              (intmax_t) ts[1].tv_sec, (intmax_t) ts[1].tv_usec,
+              ts + 2, rc, errno2name());
+
        (void) close(0);
        rc = syscall(__NR_futimesat, 0, "", ts);
        printf("futimesat(0, \"\", [{tv_sec=%jd, tv_usec=%jd}, "
index 1a2c9495e5c865cf78321e108d82b7c4b493de89..bbfa03105408efbafb7e00349b98a0fdfa3b2126 100644 (file)
@@ -52,15 +52,20 @@ main(void)
 
        struct timeval *const ts = tail_alloc(sizeof(*ts) * 2);
 
-       rc = syscall(__NR_utimes, 0, ts + 1);
-       printf("utimes(NULL, %p) = %ld %s (%m)\n",
-              ts + 1, rc, errno2name());
-
        ts[0].tv_sec = tv.tv_sec;
        ts[0].tv_usec = tv.tv_usec;
        ts[1].tv_sec = tv.tv_sec - 1;
        ts[1].tv_usec = tv.tv_usec + 1;
 
+       rc = syscall(__NR_utimes, 0, ts + 2);
+       printf("utimes(NULL, %p) = %ld %s (%m)\n", ts + 2, rc, errno2name());
+
+       rc = syscall(__NR_utimes, 0, ts + 1);
+       printf("utimes(NULL, [{tv_sec=%jd, tv_usec=%jd}, %p]) = "
+              "%ld %s (%m)\n",
+              (intmax_t) ts[1].tv_sec, (intmax_t) ts[1].tv_usec,
+              ts + 2, rc, errno2name());
+
        rc = syscall(__NR_utimes, "", ts);
        printf("utimes(\"\", [{tv_sec=%jd, tv_usec=%jd}, "
               "{tv_sec=%jd, tv_usec=%jd}]) = %ld %s (%m)\n",