[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: $(wildcard ...*/) and symlinks

From: Paul Smith
Subject: Re: $(wildcard ...*/) and symlinks
Date: Sat, 25 Feb 2023 09:27:15 -0500
User-agent: Evolution 3.46.4 (by Flathub.org)

On Fri, 2023-02-24 at 10:05 -0500, Dmitry Goncharov wrote:
> On Fri, Feb 24, 2023 at 6:55 AM Frank Heckenbach
> <f.heckenbach@fh-soft.de> wrote:
> ...
> > So "*/" ignores the symlink to a file as expected, but "l*/" does
> > return it, likewise "*/*/" which doesn't make much sense to me.
> There is a known bug in glibc glob impl.
> The current impl of glob handles trailing slashes correctly on
> certain filesystems and fails on others.  See 
> https://lists.gnu.org/archive/html/bug-gnulib/2019-11/msg00006.html

As Dmitry says, this is an unfortunate bug in GNU libc glob, not in GNU
make.  That patch was reported in 2019 and I'm not sure the fix has
ever been applied.  However, glob(3) is still broken in my instance of
GNU libc which is 2.35, just over a year old.  This is on Linux ext4.

It may be related to this:
but if not, maybe it would be good for Dmitry to file a new bug against
GNU libc glob with the patch he provided in 2019 as it seems to have
gotten lost.

Here's a test case written for GNU libc glob, without any GNU make
special casing, which shows the same behavior as GNU make's wildcard
given the environment in the "prepare" target of the makefile you gave:

---- 8>< ----
$ cat glob.c
#include <stdio.h>
#include <glob.h>

int main(int argc, char *argv[])
    glob_t gl = {0};
    int r = glob(argv[1], 0, NULL, &gl);
    if (r != 0) {
        printf("error: %s\n", (r == GLOB_NOSPACE ? "NOSPACE"
                               : r == GLOB_ABORTED ? "ABORTED"
                               : r == GLOB_NOMATCH ? "NOMATCH"
                               : "UNKNOWN"));
        return 1;
    for (size_t i = 0; i < gl.gl_pathc; ++i) {
        printf("match: %s\n", gl.gl_pathv[i]);
    return 0;

$ gcc -o glob glob.c

$ ./glob '*/'
match: d/

$ ./glob 'l*/'
match: l

$ ./glob '*/*/'
match: d/d/
match: d/l

reply via email to

[Prev in Thread] Current Thread [Next in Thread]