From 385a67dc6aec2ac34b65099bddd157c88fdf4fda Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sun, 26 Mar 2017 19:47:43 +0000 Subject: [PATCH] diff: Show nanoseconds in -u/-c header line. Show nanoseconds in the -u/-c header line. The present portability conditionals cannot handle the POSIX standard st_mtim, so remove them and unconditionally use st_mtim. PR: 218018 Reported by: jbeich Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D10145 --- usr.bin/diff/diffreg.c | 16 +++------------- usr.bin/diff/tests/Makefile | 3 ++- usr.bin/diff/tests/diff_test.sh | 13 +++++++++++++ usr.bin/diff/tests/header_ns.out | 4 ++++ 4 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 usr.bin/diff/tests/header_ns.out diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 55530b9bfa5e..99bfb0530e66 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -94,12 +94,6 @@ __FBSDID("$FreeBSD$"); #define _PATH_PR "/usr/bin/pr" -#ifdef ST_MTIM_NSEC -# define TIMESPEC_NS(timespec) ((timespec).ST_MTIM_NSEC) -#else -# define TIMESPEC_NS(timespec) 0 -#endif - /* * diff - compare two files. */ @@ -1615,14 +1609,10 @@ print_header(const char *file1, const char *file2) char end1[10]; char end2[10]; struct tm tm1, tm2, *tm_ptr1, *tm_ptr2; - int nsec1 = TIMESPEC_NS (stb1.st_mtime); - int nsec2 = TIMESPEC_NS (stb2.st_mtime); + int nsec1 = stb1.st_mtim.tv_nsec; + int nsec2 = stb2.st_mtim.tv_nsec; -#ifdef ST_MTIM_NSEC - time_format = "%Y-%m-%d %H:%M:%S.%N"; -#else - time_format = "%Y-%m-%d %H:%M:%S"; -#endif + time_format = "%Y-%m-%d %H:%M:%S"; if (cflag) time_format = "%c"; diff --git a/usr.bin/diff/tests/Makefile b/usr.bin/diff/tests/Makefile index d09b24c24a71..4dfa372f2c4d 100644 --- a/usr.bin/diff/tests/Makefile +++ b/usr.bin/diff/tests/Makefile @@ -20,7 +20,8 @@ ${PACKAGE}FILES+= \ unified_p.out \ unified_c9999.out \ unified_9999.out \ - header.out + header.out \ + header_ns.out NETBSD_ATF_TESTS_SH+= netbsd_diff_test diff --git a/usr.bin/diff/tests/diff_test.sh b/usr.bin/diff/tests/diff_test.sh index 6ea67d880409..c712d5871480 100755 --- a/usr.bin/diff/tests/diff_test.sh +++ b/usr.bin/diff/tests/diff_test.sh @@ -3,6 +3,7 @@ atf_test_case simple atf_test_case unified atf_test_case header +atf_test_case header_ns simple_body() { @@ -58,9 +59,21 @@ header_body() diff -u empty hello } +header_ns_body() +{ + export TZ=UTC + : > empty + echo hello > hello + touch -d 2015-04-03T01:02:03.123456789 empty + touch -d 2016-12-22T11:22:33.987654321 hello + atf_check -o "file:$(atf_get_srcdir)/header_ns.out" -s eq:1 \ + diff -u empty hello +} + atf_init_test_cases() { atf_add_test_case simple atf_add_test_case unified atf_add_test_case header + atf_add_test_case header_ns } diff --git a/usr.bin/diff/tests/header_ns.out b/usr.bin/diff/tests/header_ns.out new file mode 100644 index 000000000000..b1316dfc12b9 --- /dev/null +++ b/usr.bin/diff/tests/header_ns.out @@ -0,0 +1,4 @@ +--- empty 2015-04-03 01:02:03.123456789 +0000 ++++ hello 2016-12-22 11:22:33.987654321 +0000 +@@ -0,0 +1 @@ ++hello