]> granicus.if.org Git - strace/commitdiff
tests: transform print_time_t into print_time_t_nsec
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 26 Feb 2017 23:23:31 +0000 (23:23 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 26 Feb 2017 23:23:31 +0000 (23:23 +0000)
* tests/print_time.c (print_time_t): Rename to print_time_t_nsec,
take second argument and print it.
* tests/tests.h (print_time_t): Rename to print_time_t_nsec,
add second argument.
* tests/utime.c (main): Use print_time_t_nsec instead of print_time_t.
* tests/xstatx.c (print_stat): Likewise.  Pass nanoseconds
to print_time_t_nsec instead of printing them.

tests/print_time.c
tests/tests.h
tests/utime.c
tests/xstatx.c

index c30a858dfe54826eb932370844deaa35c1b9e674..6a3cfb5727498677a8f891cec8c9e9499a85406b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Print time_t in symbolic format.
+ * Print time_t and nanoseconds in symbolic format.
  *
  * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
  * All rights reserved.
 #include <time.h>
 
 void
-print_time_t(const time_t t)
+print_time_t_nsec(const time_t t, const unsigned long long nsec)
 {
-       if (!t) {
-               putchar('0');
-               return;
-       }
-
-       const struct tm *const p = localtime(&t);
+       if (t) {
+               const struct tm *const p = localtime(&t);
 
-       if (p) {
-               char buf[256];
+               if (p) {
+                       char buf[256];
 
-               strftime(buf, sizeof(buf), "%FT%T%z", p);
-               fputs(buf, stdout);
+                       strftime(buf, sizeof(buf), "%FT%T%z", p);
+                       fputs(buf, stdout);
+               } else {
+                       printf("%llu", zero_extend_signed_to_ull(t));
+               }
        } else {
-               printf("%llu", zero_extend_signed_to_ull(t));
+               putchar('0');
+       }
+
+       if (nsec) {
+               printf(".%09llu", nsec);
        }
 }
index 38fd0b0dd8fe6fc20ed872fc6cc31371af1a1b55..7a398c18ebf55af7fa8a6726dc5488547eb10326 100644 (file)
@@ -103,8 +103,8 @@ void print_quoted_string(const char *);
 /* Print memory in a quoted form. */
 void print_quoted_memory(const char *, size_t);
 
-/* Print time_t in symbolic format. */
-void print_time_t(time_t);
+/* Print time_t and nanoseconds in symbolic format. */
+void print_time_t_nsec(time_t, unsigned long long);
 
 /* Read an int from the file. */
 int read_int_from_file(const char *, int *);
index 7c9b60876760639a991b8195c91b3205703bacab..ba8ae32633cf8d34a8d97e63de9fa50d0202beed 100644 (file)
@@ -69,9 +69,9 @@ main(void)
        rc = k_utime("utime\nfilename", tail_u);
        const char *errstr = sprintrc(rc);
        printf("utime(\"utime\\nfilename\", {actime=");
-       print_time_t(t);
+       print_time_t_nsec(t, 0);
        printf(", modtime=");
-       print_time_t(t);
+       print_time_t_nsec(t, 0);
        printf("}) = %s\n", errstr);
 
        puts("+++ exited with 0 +++");
index bb88f2efe872d70b8094404b56c06eb9245c532f..874f3090289d5fadb2d9cb2122ffbb6940d07614 100644 (file)
@@ -162,17 +162,15 @@ print_stat(const STRUCT_STAT *st)
        }
 
 # if defined(HAVE_STRUCT_STAT_ST_MTIME_NSEC) && !OLD_STAT
-#  define PRINT_TIME_NSEC(val)                                         \
-       if (val)                                                        \
-               printf(".%09llu", zero_extend_signed_to_ull(val))
+#  define TIME_NSEC(val)       zero_extend_signed_to_ull(val)
 # else
-#  define PRINT_TIME_NSEC(val)
+#  define TIME_NSEC(val)       0
 # endif
 
 # define PRINT_ST_TIME(field)                                          \
        printf(", st_" #field "=");                                     \
-       print_time_t(sign_extend_unsigned_to_ll(st->st_ ## field));     \
-       PRINT_TIME_NSEC(st->st_ ## field ## _nsec)
+       print_time_t_nsec(sign_extend_unsigned_to_ll(st->st_ ## field), \
+                         TIME_NSEC(st->st_ ## field ## _nsec))
 
        PRINT_ST_TIME(atime);
        PRINT_ST_TIME(mtime);