]> git.ipfire.org Git - thirdparty/make.git/commit
* src/dir.c: Preserve glob d_type field
authorspagoveanu@gmail.com <spagoveanu@gmail.com>
Tue, 19 Jun 2018 23:03:48 +0000 (02:03 +0300)
committerPaul Smith <psmith@gnu.org>
Fri, 3 Aug 2018 00:59:02 +0000 (20:59 -0400)
commitb7acb10e86dc8f5fdf2a2bbd87e1059c315e31d6
treeb171c8095507d339b8b4d38a3bc1811367eb4f4d
parentb36a8ec92af14f3b25962a4e0c0aa7818f336359
* src/dir.c: Preserve glob d_type field

When using GNU make on a system with glibc glob a pattern ending in
a slash is also matching regular files, but only in subdirectories:

$ mkdir -p dir/subdir
$ cd dir
$ touch file1 subdir/file2
$ echo 'test:; @echo $(wildcard */ */*/)' | make -f -
subdir/ subdir/file2
$ echo 'test: */ */*/; @echo "$?" != */ */*/' | make -f -
subdir/ subdir/file2 != subdir/ */*/

It happens because in the gl->gl_readdir callback supplied to glob(),
dirent->d_type is set to DT_UNKNOWN, and the glob() implementation
in glibc assumes that such a directory entry *cannot* possibly be a
regular file.

Pass the actual d_type down to glob(); this is the right thing to do
even if glibc is fixed, because it saves an extra stat() syscall for
each dirent.

Copyright-paperwork-exempt: yes
src/dir.c