GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::filesystem::perm_options(3) C++ Standard Libary std::filesystem::perm_options(3)

std::filesystem::perm_options - std::filesystem::perm_options


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)


At most one of add, remove, replace may be present, otherwise the behavior of the
permissions function is undefined.


Member constant Meaning
replace Permissions will be completely replaced by the argument to
permissions() (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

// Run this code


#include <fstream>
#include <bitset>
#include <iostream>
#include <filesystem>
namespace fs = std::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::owner_all | fs::perms::group_all,
fs::perm_options::add);


std::cout << "After adding u+rwx and g+rwx: ";
demo_perms(fs::status("test.txt").permissions());


fs::remove("test.txt");
}


Created file with permissions: rw-r--r--
After adding u+rwx and g+wrx: rwxrwxr--


permissions modifies file access permissions
(C++17) (function)
perms identifies file system permissions
(C++17) (enum)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.