[PATCH] posix: if glob has a trailing slash match directories only.

Paul Eggert eggert@cs.ucla.edu
Wed Nov 29 23:01:00 GMT 2017


On 11/29/2017 01:50 PM, Dmitry Goncharov wrote:
> One option is we can decide the patch is compatible and apply it.

It's compatible only if we ignore performance. But I don't think that 
would be right: I expect that some callers expect GLOB_ONLYDIR to be 
fast (because that's what the Glibc documentation says), and that they 
will be disappointed by this performance regression.

> If the existing semantics has to be preserved then we can introduce
> another flag and use the new flag instead of GLOB_ONLYDIR in
>
>    if (pattern[0] && pattern[strlen (pattern) - 1] == '/')
>      flags |= GLOB_ONLYDIR;

That would be a better approach. Another possibility might be to change 
the last assignment to:

     flags |= GLOB_ONLYDIR | GLOB_MARK;

and then at the end, filter out all matches that aren't marked with 
trailing '/'. This would avoid creating a new GLOB_XXX option and would 
probably be easier to implement.



More information about the Libc-alpha mailing list