Index: usr.bin/diff/diffdir.c =================================================================== --- usr.bin/diff/diffdir.c +++ usr.bin/diff/diffdir.c @@ -37,7 +37,8 @@ #include "diff.h" static int selectfile(const struct dirent *); -static void diffit(struct dirent *, char *, size_t, char *, size_t, int); +static void diffit(struct dirent *, char *, size_t, struct dirent *, + char *, size_t, int); static void print_only(const char *, size_t, const char *); #define d_status d_type /* we need to store status for -l */ @@ -127,14 +128,14 @@ strcmp(dent1->d_name, dent2->d_name) ; if (pos == 0) { /* file exists in both dirs, diff it */ - diffit(dent1, path1, dirlen1, path2, dirlen2, flags); + diffit(dent1, path1, dirlen1, dent2, path2, dirlen2, flags); dp1++; dp2++; } else if (pos < 0) { /* file only in first dir, only diff if -N */ if (Nflag) { - diffit(dent1, path1, dirlen1, path2, dirlen2, - flags); + diffit(dent1, path1, dirlen1, dent2, path2, + dirlen2, flags); } else { print_only(path1, dirlen1, dent1->d_name); status |= 1; @@ -143,8 +144,8 @@ } else { /* file only in second dir, only diff if -N or -P */ if (Nflag || Pflag) - diffit(dent2, path1, dirlen1, path2, dirlen2, - flags); + diffit(dent2, path1, dirlen1, dent1, path2, + dirlen2, flags); else { print_only(path2, dirlen2, dent2->d_name); status |= 1; @@ -170,8 +171,8 @@ * Do the actual diff by calling either diffreg() or diffdir(). */ static void -diffit(struct dirent *dp, char *path1, size_t plen1, char *path2, size_t plen2, - int flags) +diffit(struct dirent *dp, char *path1, size_t plen1, struct dirent *dp2, + char *path2, size_t plen2, int flags) { flags |= D_HEADER; strlcpy(path1 + plen1, dp->d_name, PATH_MAX - plen1); @@ -184,7 +185,14 @@ memset(&stb1, 0, sizeof(stb1)); } - strlcpy(path2 + plen2, dp->d_name, PATH_MAX - plen2); + /* + * If we are ignoring file case, use dent2s name here if both names are + * the same apart from case. + */ + if (ignore_file_case && strcasecmp(dp2->d_name, dp2->d_name) == 0) + strlcpy(path2 + plen2, dp2->d_name, PATH_MAX - plen2); + else + strlcpy(path2 + plen2, dp->d_name, PATH_MAX - plen2); if (stat(path2, &stb2) != 0) { if (!Nflag || errno != ENOENT) { warn("%s", path2); Index: usr.bin/diff/tests/diff_test.sh =================================================================== --- usr.bin/diff/tests/diff_test.sh +++ usr.bin/diff/tests/diff_test.sh @@ -19,6 +19,7 @@ atf_test_case report_identical atf_test_case non_regular_file atf_test_case binary +atf_test_case ignorecase simple_body() { @@ -278,6 +279,17 @@ atf_check -o inline:"176c\nx\n.\n" -s exit:1 diff -ae A B } +ignorecase_body() +{ + atf_check mkdir A + atf_check mkdir B + + atf_check -x "echo hello > A/foo" + atf_check -x "echo hello > B/FOO" + + atf_check -o empty -s exit:0 diff -u -r --ignore-file-name-case A B +} + atf_init_test_cases() { atf_add_test_case simple @@ -299,4 +311,5 @@ atf_add_test_case report_identical atf_add_test_case non_regular_file atf_add_test_case binary + atf_add_test_case ignorecase }