glob 是否应该使用 GLOB_MARK 将 / 附加到符号链接到目录结果?

发布于 2024-12-28 12:26:34 字数 592 浏览 3 评论 0原文

glob 函数有一个 GLOB_MARK 标志,指定将斜杠附加到目录结果中:

GLOB_MARK

作为与模式匹配的目录的每个路径名都应附加一个

(来源:http://pubs.opengroup.org/onlinepubs/9699919799/functions/ glob.html

但是,据我所知,没有提供有关此功能如何工作的更多详细信息。特别是,如果结果本身不是目录,而是目录的符号链接,是否应该附加斜杠? glibc 实现就是这样做的。

我知道鉴于 glob 标准的简洁性,这是一个很难回答的问题,因此好的答案是引用 POSIX 之外的历史实践、历史标准或文档,这些文档可能会进一步指定 glob 的行为glob 等。提出一种行为或另一种行为更有用的原因的答案也会很有趣。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短叹 2025-01-04 12:26:34

来自我自己团队的非官方研究分支:;-)

glob(3) 于 1989 年首次出现在 bsd4.3-reno 中,并在带有 GLOB_MARK 的目录符号链接后附加“/”

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

(glob2 在路径缓冲区上使用 stat,而不是 lstat)

solaris 有一个带有 1985 年版权注释的 glob

那个也将“/”添加到符号链接路径

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文