Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 426
R.. GitHub STOP HELPING ICE Avatar asked Jan 23 '12 00:01

R.. GitHub STOP HELPING ICE


1 Answers

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

like image 150
R.. GitHub STOP HELPING ICE Avatar answered Nov 01 '22 13:11

R.. GitHub STOP HELPING ICE