2

(This is intended as a specific query regarding the newer standards like C++17)

the filesystem headers now provide a way to get the permissions on a path, formatted in the standard 3 perms way (owner, group, other).

How would one determine which of these is the relevant permission? (is the executing program the owner, a member of a group with access permissions, or a member of neither and thus "other")

I'm looking for a native cross platform way of doing it, if this isn't yet possible, let me know that. The intent is to avoid farming this duty out manually to explicit unix commands or windows library functions in my own code if I can avoid doing so.

Ðаn
  • 10,934
  • 11
  • 59
  • 95
KotoroShinoto
  • 720
  • 1
  • 5
  • 9
  • The permissions themselves are barely portable—FAT has a single read-only bit, and modern filesystems support ACLs (more widely utilized on Windows). I’m not sure asking questions about their _interpretation_ is even meaningful. – Davis Herring Jan 23 '20 at 18:47

1 Answers1

1

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.

Jaffa
  • 12,442
  • 4
  • 49
  • 101