diff options
author | Jilles Tjoelker <jilles@FreeBSD.org> | 2017-03-26 14:09:25 +0000 |
---|---|---|
committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2017-03-26 14:09:25 +0000 |
commit | 58cf4d864f54b697ce69078c90d338ed3580821d (patch) | |
tree | bfecc244930d6d1cd0ea1994f5129ba31bc2c694 /usr.bin/diff | |
parent | d91400bf981b6226dd3fb60d538249f474153fc0 (diff) | |
download | src-test2-58cf4d864f54b697ce69078c90d338ed3580821d.tar.gz src-test2-58cf4d864f54b697ce69078c90d338ed3580821d.zip |
diff: Fix mtime of file1 in -u/-c header line.
PR: 218018
Reviewed by: bapt
Differential Revision: https://reviews.freebsd.org/D10140
Notes
Notes:
svn path=/head/; revision=315985
Diffstat (limited to 'usr.bin/diff')
-rw-r--r-- | usr.bin/diff/diffreg.c | 6 | ||||
-rw-r--r-- | usr.bin/diff/tests/Makefile | 3 | ||||
-rwxr-xr-x | usr.bin/diff/tests/diff_test.sh | 13 | ||||
-rw-r--r-- | usr.bin/diff/tests/header.out | 4 |
4 files changed, 22 insertions, 4 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 6c5d8fa91844..55530b9bfa5e 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1614,7 +1614,7 @@ print_header(const char *file1, const char *file2) char buf2[256]; char end1[10]; char end2[10]; - struct tm *tm_ptr1, *tm_ptr2; + struct tm tm1, tm2, *tm_ptr1, *tm_ptr2; int nsec1 = TIMESPEC_NS (stb1.st_mtime); int nsec2 = TIMESPEC_NS (stb2.st_mtime); @@ -1626,8 +1626,8 @@ print_header(const char *file1, const char *file2) if (cflag) time_format = "%c"; - tm_ptr1 = localtime(&stb1.st_mtime); - tm_ptr2 = localtime(&stb2.st_mtime); + tm_ptr1 = localtime_r(&stb1.st_mtime, &tm1); + tm_ptr2 = localtime_r(&stb2.st_mtime, &tm2); strftime(buf1, 256, time_format, tm_ptr1); strftime(buf2, 256, time_format, tm_ptr2); if (!cflag) { diff --git a/usr.bin/diff/tests/Makefile b/usr.bin/diff/tests/Makefile index 6b1c824fb5ba..d09b24c24a71 100644 --- a/usr.bin/diff/tests/Makefile +++ b/usr.bin/diff/tests/Makefile @@ -19,7 +19,8 @@ ${PACKAGE}FILES+= \ simple_p.out \ unified_p.out \ unified_c9999.out \ - unified_9999.out + unified_9999.out \ + header.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 cd2c47063774..6ea67d880409 100755 --- a/usr.bin/diff/tests/diff_test.sh +++ b/usr.bin/diff/tests/diff_test.sh @@ -2,6 +2,7 @@ atf_test_case simple atf_test_case unified +atf_test_case header simple_body() { @@ -46,8 +47,20 @@ unified_body() diff -u9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in" } +header_body() +{ + export TZ=UTC + : > empty + echo hello > hello + touch -d 2015-04-03T01:02:03 empty + touch -d 2016-12-22T11:22:33 hello + atf_check -o "file:$(atf_get_srcdir)/header.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 } diff --git a/usr.bin/diff/tests/header.out b/usr.bin/diff/tests/header.out new file mode 100644 index 000000000000..2e1665a30e6d --- /dev/null +++ b/usr.bin/diff/tests/header.out @@ -0,0 +1,4 @@ +--- empty 2015-04-03 01:02:03.000000000 +0000 ++++ hello 2016-12-22 11:22:33.000000000 +0000 +@@ -0,0 +1 @@ ++hello |