Index: contrib/netbsd-tests/usr.bin/cmp/t_cmp.sh =================================================================== --- contrib/netbsd-tests/usr.bin/cmp/t_cmp.sh +++ contrib/netbsd-tests/usr.bin/cmp/t_cmp.sh @@ -60,8 +60,46 @@ atf_check -s exit:1 -o not-empty -e empty -x "cmp a b '9'" } +atf_test_case special +special_head() { + atf_set "descr" "Test cmp(1)'s handling of non-regular files" +} +special_body() { + echo 0123456789abcdef > a + echo 0123456789abcdeg > b + cat a | atf_check -s exit:0 -x "cmp a -" + cat a | atf_check -s exit:0 -x "cmp - a" + cat b | atf_check -s not-exit:0 -x "cmp a -" + cat b | atf_check -s not-exit:0 -x "cmp - a" + true +} + +atf_test_case symlink +symlink_head() { + atf_set "descr" "Test cmp(1)'s handling of symlinks" +} +symlink_body() { + echo 0123456789abcdef > a + echo 0123456789abcdeg > b + ln -s a a.lnk + ln -s b b.lnk + ln -s a a2.lnk + cp a adup + ln -s adup adup.lnk + atf_check -s exit:0 -x "cmp a a.lnk" + atf_check -s exit:0 -x "cmp a.lnk a" + atf_check -s not-exit:0 -o ignore -x "cmp a b.lnk" + atf_check -s not-exit:0 -o ignore -x "cmp b.lnk a" + atf_check -s not-exit:0 -o ignore -x -e ignore "cmp -h a a.lnk" + atf_check -s not-exit:0 -o ignore -e ignore -x "cmp -h a.lnk a" + atf_check -s exit:0 -x "cmp -h a.lnk a2.lnk" + atf_check -s not-exit:0 -o ignore -e ignore -x "cmp -h a.lnk adup.lnk" +} + atf_init_test_cases() { atf_add_test_case missing atf_add_test_case skip + atf_add_test_case special + atf_add_test_case symlink } Index: usr.bin/cmp/special.c =================================================================== --- usr.bin/cmp/special.c +++ usr.bin/cmp/special.c @@ -99,6 +99,7 @@ } else if (feof(fp2)) eofmsg(file2); + fclose(fp1); if (dfound) exit(DIFF_EXIT); }