Search code examples
cposixgloblanguage-lawyer

Should glob, with GLOB_MARK, append / to symlink-to-directory results?


The glob function has a GLOB_MARK flag that's specified to append a slash to results which are directories:

GLOB_MARK

Each pathname that is a directory that matches pattern shall have a <slash> appended.

(Source: http://pubs.opengroup.org/onlinepubs/9699919799/functions/glob.html)

However, as far as I can tell, no further details are provided on how this feature is supposed to work. In particular, if a result is not a directory itself, but is a symbolic link to a directory, should a slash be appended? The glibc implementation does this.

I know this is a hard question to answer given the terseness of the standard for glob, so good answers will be ones that cite historical practice, historical standards or documentation other than POSIX that might further specify the behavior of glob, etc. Answers which bring up reasons why one behavior or the other is more useful would also be interesting.


Solution

  • From my own team's unofficial research branch: ;-)

    glob(3) first appeared in bsd4.3-reno in 1989 and it appended '/' after directory symlinks with GLOB_MARK

    http://minnie.tuhs.org/cgi-bin/utree.pl?file=4.3BSD-Reno/src/lib/libc/gen/glob.c

    (glob2 uses stat, not lstat on the pathbuf)

    solaris has a glob with copyright comment from 1985

    that one adds '/' to symlink paths as well