Author: jilles
Date: Sun Mar 26 19:47:43 2017
New Revision: 316002
URL: https://svnweb.freebsd.org/changeset/base/316002

Log:
  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

Added:
  head/usr.bin/diff/tests/header_ns.out   (contents, props changed)
Modified:
  head/usr.bin/diff/diffreg.c
  head/usr.bin/diff/tests/Makefile
  head/usr.bin/diff/tests/diff_test.sh

Modified: head/usr.bin/diff/diffreg.c
==============================================================================
--- head/usr.bin/diff/diffreg.c Sun Mar 26 18:46:35 2017        (r316001)
+++ head/usr.bin/diff/diffreg.c Sun Mar 26 19:47:43 2017        (r316002)
@@ -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 ch
        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";

Modified: head/usr.bin/diff/tests/Makefile
==============================================================================
--- head/usr.bin/diff/tests/Makefile    Sun Mar 26 18:46:35 2017        
(r316001)
+++ head/usr.bin/diff/tests/Makefile    Sun Mar 26 19:47:43 2017        
(r316002)
@@ -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
 

Modified: head/usr.bin/diff/tests/diff_test.sh
==============================================================================
--- head/usr.bin/diff/tests/diff_test.sh        Sun Mar 26 18:46:35 2017        
(r316001)
+++ head/usr.bin/diff/tests/diff_test.sh        Sun Mar 26 19:47:43 2017        
(r316002)
@@ -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
 }

Added: head/usr.bin/diff/tests/header_ns.out
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/usr.bin/diff/tests/header_ns.out       Sun Mar 26 19:47:43 2017        
(r316002)
@@ -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
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to