std::filesy...perm_options(3)
β¨ NAME β¨
std::filesystem::perm_options β okay bestie, this is the std::filesy...perm_options(3) page from the C++ Standard Libary manual, and it is literally all about the std::filesystem::perm_options type. π
πΈ Synopsis πΈ
Defined in header <filesystem> π
enum class perm_options {
replace = /* unspecified */,
add = /* unspecified */, (since C++17)
remove = /* unspecified */,
nofollow = /* unspecified */
};
This type represents available options that control the behavior of the function std::filesystem::permissions().
perm_options satisfies the requirements of BitmaskType β which means the bitwise operators operator&, operator|, operator^, operator~, operator&=, operator|=, and operator^= are defined for this type. slay. β¨
π Member constants π
π¨ At most one ofadd,remove,replacemay be present, otherwise the behavior of thepermissionsfunction is undefined.
Here's the member constant tea, no cap:
replaceβ Permissions will be completely replaced by the argument topermissions()(default behavior). πaddβ Permissions will be replaced by the bitwise OR of the argument and the current permissions. πΈremoveβ Permissions will be replaced by the bitwise AND of the negated argument and current permissions. π¦nofollowβ Permissions will be changed on the symlink itself, rather than on the file it resolves to. π
π§ͺ Example π§ͺ
// Run this code
#include <filesystem>
#include <fstream>
#include <iostream>
void demo_perms(std::filesystem::perms p)
{
using std::filesystem::perms;
auto show = [=](char op, perms perm)
{
std::cout << (perms::none == (perm & p) ? '-' : op);
};
show('r', perms::owner_read);
show('w', perms::owner_write);
show('x', perms::owner_exec);
show('r', perms::group_read);
show('w', perms::group_write);
show('x', perms::group_exec);
show('r', perms::others_read);
show('w', perms::others_write);
show('x', perms::others_exec);
std::cout << '\n';
}
int main()
{
std::ofstream("test.txt"); // create file
std::cout << "Created file with permissions: ";
demo_perms(std::filesystem::status("test.txt").permissions());
std::filesystem::permissions(
"test.txt",
std::filesystem::perms::owner_all |
std::filesystem::perms::group_all,
std::filesystem::perm_options::add
);
std::cout << "After adding u+rwx and g+rwx: ";
demo_perms(std::filesystem::status("test.txt").permissions());
std::filesystem::remove("test.txt");
}
π Possible output π
Created file with permissions: rw-r--r--
After adding u+rwx and g+wrx: rwxrwxr--
π See also π
permissionsβ modifies file access permissions (C++17) (function)permsβ identifies file system permissions (C++17) (enum)
π source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::filesy...perm_options(3) β that's the whole page, bestie! byeeee π«Άβ¨
π¦ 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