std::experi...stem::perms(3)
okay so welcome to the C++ Standard Libary page for std::experimental::filesystem::perms β that's the man page std::experi...stem::perms(3), and we're about to make file permissions make sense, no cap π
β¨ NAME β¨
std::experimental::filesystem::perms β std::experimental::filesystem::perms (yes bestie, the NAME section said it twice and we're keeping the whole vibe).
π¦ Synopsis π¦
Defined in header <experimental/filesystem>:
enum class perms; (filesystem TS)
So perms is the type that represents file access permissions. It satisfies the requirements of BitmaskType β meaning operator&, operator|, operator^, operator~, operator&=, operator|=, and operator^= are defined for this type. Bitmask icon behavior, periodt β¨
Access permissions model POSIX permission bits, and any individual file permissions (as reported by status) are a combination of some of the following bits:
π Member constants π
The original columns are Member constant, Value (octal), POSIX equivalent, and Meaning β here they are as bullet points so nobody's eyes glaze over π
noneβ value (octal):0; POSIX equivalent: none listed. No permission bits are set.owner_readβ value (octal):0400; POSIX equivalent:S_IRUSR. File owner has read permission.owner_writeβ value (octal):0200; POSIX equivalent:S_IWUSR. File owner has write permission.owner_execβ value (octal):0100; POSIX equivalent:S_IXUSR. File owner has execute/search permission.owner_allβ value (octal):0700; POSIX equivalent:S_IRWXU. File owner has read, write, and execute/search permissions; equivalent toowner_read | owner_write | owner_exec.group_readβ value (octal):040; POSIX equivalent:S_IRGRP. The file's user group has read permission.group_writeβ value (octal):020; POSIX equivalent:S_IWGRP. The file's user group has write permission.group_execβ value (octal):010; POSIX equivalent:S_IXGRP. The file's user group has execute/search permission.group_allβ value (octal):070; POSIX equivalent:S_IRWXG. The file's user group has read, write, and execute/search permissions; equivalent togroup_read | group_write | group_exec.others_readβ value (octal):04; POSIX equivalent:S_IROTH. Other users have read permission.others_writeβ value (octal):02; POSIX equivalent:S_IWOTH. Other users have write permission.others_execβ value (octal):01; POSIX equivalent:S_IXOTH. Other users have execute/search permission.others_allβ value (octal):07; POSIX equivalent:S_IRWXO. Other users have read, write, and execute/search permissions; equivalent toothers_read | others_write | others_exec.allβ value (octal):0777; POSIX equivalent: none listed. All users have read, write, and execute/search permissions; equivalent toowner_all | group_all | others_all.set_uidβ value (octal):04000; POSIX equivalent:S_ISUID. Set user ID to file owner user ID on execution.set_gidβ value (octal):02000; POSIX equivalent:S_ISGID. Set group ID to file's user group ID on execution.sticky_bitβ value (octal):01000; POSIX equivalent:S_ISVTX. Implementation-defined meaning, but POSIX XSI specifies that when set on a directory, only file owners may delete files even if the directory is writeable to others (used with/tmp).maskβ value (octal):07777; POSIX equivalent: none listed. All valid permission bits; equivalent toall | set_uid | set_gid | sticky_bit.
Additionally, the following constants of this type are defined, which do not represent permissions. The columns are Member constant, Value (hex), and Meaning:
unknownβ value (hex):0xFFFF. Unknown permissions (e.g. whenfile_statusis created without permissions).add_permsβ value (hex):0x10000. Control bit that instructspermissionsto add, but not clear permission bits.remove_permsβ value (hex):0x20000. Control bit that instructspermissionsto clear, but not add permission bits.resolve_symlinksβ value (hex):0x40000. Control bit that instructspermissionsto resolve symlinks.
π Notes π
Permissions may not necessarily be implemented as bits, but they are treated that way conceptually.
Some permission bits may be ignored on some systems, and changing some bits may automatically change others (e.g. on platforms without owner/group/all distinction, setting any of the three write bits set all three).
π₯ Example π₯
// Run this code
#include <bitset>
#include <experimental/filesystem>
#include <fstream>
#include <iostream>
namespace fs = std::experimental::filesystem;
void demo_perms(fs::perms p)
{
std::cout << ((p & fs::perms::owner_read) != fs::perms::none ? "r"
: "-")
<< ((p & fs::perms::owner_write) != fs::perms::none ?
"w" : "-")
<< ((p & fs::perms::owner_exec) != fs::perms::none ? "x"
: "-")
<< ((p & fs::perms::group_read) != fs::perms::none ? "r"
: "-")
<< ((p & fs::perms::group_write) != fs::perms::none ?
"w" : "-")
<< ((p & fs::perms::group_exec) != fs::perms::none ? "x"
: "-")
<< ((p & fs::perms::others_read) != fs::perms::none ?
"r" : "-")
<< ((p & fs::perms::others_write) != fs::perms::none ?
"w" : "-")
<< ((p & fs::perms::others_exec) != fs::perms::none ?
"x" : "-")
<< '\n';
}
int main()
{
std::ofstream("test.txt"); // create file
std::cout << "Created file with permissions: ";
demo_perms(fs::status("test.txt").permissions());
fs::permissions("test.txt", fs::perms::add_perms |
fs::perms::owner_all |
fs::perms::group_all);
std::cout << "After adding o+rwx and g+rwx: ";
demo_perms(fs::status("test.txt").permissions());
fs::remove("test.txt");
}
Possible output:
Created file with permissions: rw-r--r--
After adding o+rwx and g+rwx: rwxrwxr--
π See also π
statusβ determines file attributes.symlink_statusβ determines file attributes, checking the symlink target (function).permissionsβ modifies file access permissions (function).
π Category π
Noindexed pages
okay that's the whole page, bestie π«Ά β source/version: http://cppreference.com; date: 2024.06.10; page: std::experi...stem::perms(3). bye and slay π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms