Skip to content

Commit d094e05

Browse files
committed
diff-no-index: do not reference .d_type member of struct dirent
Some platforms like AIX lack .d_type member in "struct dirent"; use the DTYPE(e) macro instead of a direct reference to e->d_type and when it yields DT_UNKNOWN, find the real type with get_dtype(). Signed-off-by: Junio C Hamano <[email protected]>
1 parent 09fb155 commit d094e05

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

diff-no-index.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,24 @@ static int read_directory_contents(const char *path, struct string_list *list,
4141

4242
while ((e = readdir_skip_dot_and_dotdot(dir))) {
4343
if (pathspec) {
44+
int is_dir = 0;
45+
4446
strbuf_setlen(&match, len);
4547
strbuf_addstr(&match, e->d_name);
48+
if (NOT_CONSTANT(DTYPE(e)) != DT_UNKNOWN) {
49+
is_dir = (DTYPE(e) == DT_DIR);
50+
} else {
51+
struct strbuf pathbuf = STRBUF_INIT;
52+
53+
strbuf_addstr(&pathbuf, path);
54+
strbuf_complete(&pathbuf, '/');
55+
is_dir = get_dtype(e, &pathbuf, 0) == DT_DIR;
56+
strbuf_release(&pathbuf);
57+
}
4658

4759
if (!match_leading_pathspec(NULL, pathspec,
4860
match.buf, match.len,
49-
0, NULL, e->d_type == DT_DIR ? 1 : 0))
61+
0, NULL, is_dir))
5062
continue;
5163
}
5264

0 commit comments

Comments
 (0)