1

(这旨在作为有关 C++17 等较新标准的特定查询)

文件系统标头现在提供了一种获取路径权限的方法,格式为标准 3 perms 方式(所有者、组、其他)。

如何确定其中哪些是相关许可?(执行程序是所有者,是具有访问权限的组的成员,还是两者都不是的成员,因此是“其他”)

我正在寻找一种原生的跨平台方式,如果这还不可能,请告诉我。目的是避免在我自己的代码中手动将这项职责转移到显式的 unix 命令或 windows 库函数,如果我可以避免这样做的话。

4

1 回答 1

0

The std::filesystem::status returns the status of the file and the permissions as given by stat, but does not provide user and group information, so it's not possible to know which bits are relevant for the current process.

The main point here is that the standard library aims to provide portable behavior across different target platforms (Windows, Linux, Mac, ...), and it's definitely not trivial to do so for users and groups. As @Davis Herring stated in comments, even file permissions are barely portable.

The standard library is based on boost:filesystem, for which we have the same problem.

于 2020-01-24T15:06:23.777 回答