]> granicus.if.org Git - strace/blobdiff - print_timespec.c
tests: move F_OFD_SETLK* checks from fcntl64.c to fcntl-common.c
[strace] / print_timespec.c
index 76c70edbe0ab271d2af4454b96c66e31285203a9..a482f103f9541daba2f500a8e9b356fc52890a73 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2016-2018 The strace developers.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -33,6 +34,8 @@ typedef struct timespec timespec_t;
 
 #include MPERS_DEFS
 
+#include "xstring.h"
+
 #ifndef UTIME_NOW
 # define UTIME_NOW ((1l << 30) - 1l)
 #endif
@@ -40,12 +43,13 @@ typedef struct timespec timespec_t;
 # define UTIME_OMIT ((1l << 30) - 2l)
 #endif
 
-static const char timespec_fmt[] = "{tv_sec=%jd, tv_nsec=%jd}";
+static const char timespec_fmt[] = "{tv_sec=%lld, tv_nsec=%llu}";
 
 static void
 print_timespec_t(const timespec_t *t)
 {
-       tprintf(timespec_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_nsec);
+       tprintf(timespec_fmt, (long long) t->tv_sec,
+               zero_extend_signed_to_ull(t->tv_nsec));
 }
 
 static void
@@ -60,10 +64,48 @@ 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)));
                break;
        }
 }
 
+MPERS_PRINTER_DECL(bool, print_struct_timespec_data_size,
+                  const void *arg, const size_t size)
+{
+       if (size < sizeof(timespec_t)) {
+               tprints("?");
+               return false;
+       }
+
+       print_timespec_t(arg);
+       return true;
+}
+
+MPERS_PRINTER_DECL(bool, print_struct_timespec_array_data_size,
+                  const void *arg, const unsigned int nmemb,
+                  const size_t size)
+{
+       const timespec_t *ts = arg;
+       unsigned int i;
+
+       if (nmemb > size / sizeof(timespec_t)) {
+               tprints("?");
+               return false;
+       }
+
+       tprints("[");
+
+       for (i = 0; i < nmemb; i++) {
+               if (i)
+                       tprints(", ");
+               print_timespec_t(&ts[i]);
+       }
+
+       tprints("]");
+       return true;
+}
+
 MPERS_PRINTER_DECL(void, print_timespec,
                   struct tcb *const tcp, const kernel_ulong_t addr)
 {
@@ -85,10 +127,11 @@ MPERS_PRINTER_DECL(const char *, sprint_timespec,
                strcpy(buf, "NULL");
        } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
                   umove(tcp, addr, &t)) {
-               snprintf(buf, sizeof(buf), "%#" PRI_klx, addr);
+               xsprintf(buf, "%#" PRI_klx, addr);
        } else {
-               snprintf(buf, sizeof(buf), timespec_fmt,
-                        (intmax_t) t.tv_sec, (intmax_t) t.tv_nsec);
+               xsprintf(buf, timespec_fmt,
+                        (long long) t.tv_sec,
+                        zero_extend_signed_to_ull(t.tv_nsec));
        }
 
        return buf;