]> granicus.if.org Git - strace/commitdiff
tests: move print_time function to libtests
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 26 Feb 2017 20:35:37 +0000 (20:35 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 26 Feb 2017 20:35:37 +0000 (20:35 +0000)
Rename print_time function to print_time_t and move it to libtests.

* tests/print_time.c: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
* tests/tests.h (print_time_t): New prototype.
* tests/print_time.c (print_time): Remove.
(print_stat): Replace print_time with print_time_t.

tests/Makefile.am
tests/print_time.c [new file with mode: 0644]
tests/tests.h
tests/xstatx.c

index 294bf97644d4eda642d85113b060a426251f5e71..4e0ac9a7f9399ccf6d6543ae226763b9f17576b2 100644 (file)
@@ -54,6 +54,7 @@ libtests_a_SOURCES = \
        overflowuid.c \
        pipe_maxfd.c \
        print_quoted_string.c \
+       print_time.c \
        printflags.c \
        printxval.c \
        signal2name.c \
diff --git a/tests/print_time.c b/tests/print_time.c
new file mode 100644 (file)
index 0000000..c30a858
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Print time_t in symbolic format.
+ *
+ * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+#include <stdio.h>
+#include <time.h>
+
+void
+print_time_t(const time_t t)
+{
+       if (!t) {
+               putchar('0');
+               return;
+       }
+
+       const struct tm *const p = localtime(&t);
+
+       if (p) {
+               char buf[256];
+
+               strftime(buf, sizeof(buf), "%FT%T%z", p);
+               fputs(buf, stdout);
+       } else {
+               printf("%llu", zero_extend_signed_to_ull(t));
+       }
+}
index 00050b5e4a09ad9994b9da1cf334d5618faed966..38fd0b0dd8fe6fc20ed872fc6cc31371af1a1b55 100644 (file)
@@ -103,6 +103,9 @@ 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);
+
 /* Read an int from the file. */
 int read_int_from_file(const char *, int *);
 
index be66a8c19086302af29560c58e1f7f7d0a306a39..bb88f2efe872d70b8094404b56c06eb9245c532f 100644 (file)
 # include <unistd.h>
 # include <sys/sysmacros.h>
 
-static void
-print_time(const time_t t)
-{
-       if (!t) {
-               printf("0");
-               return;
-       }
-
-       struct tm *p = localtime(&t);
-
-       if (p) {
-               char buf[256];
-
-               strftime(buf, sizeof(buf), "%FT%T%z", p);
-
-               printf("%s", buf);
-       } else {
-               printf("%llu", zero_extend_signed_to_ull(t));
-       }
-}
-
 # ifndef STRUCT_STAT
 #  define STRUCT_STAT struct stat
 #  define STRUCT_STAT_STR "struct stat"
@@ -192,7 +171,7 @@ print_stat(const STRUCT_STAT *st)
 
 # define PRINT_ST_TIME(field)                                          \
        printf(", st_" #field "=");                                     \
-       print_time(sign_extend_unsigned_to_ll(st->st_ ## field));       \
+       print_time_t(sign_extend_unsigned_to_ll(st->st_ ## field));     \
        PRINT_TIME_NSEC(st->st_ ## field ## _nsec)
 
        PRINT_ST_TIME(atime);