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::experimental::filesystem::permissions(3) C++ Standard Libary std::experimental::filesystem::permissions(3)

std::experimental::filesystem::permissions - std::experimental::filesystem::permissions


Defined in header <experimental/filesystem>
void permissions(const path& p, perms prms); (filesystem TS)
void permissions(const path& p, perms prms, error_code& ec);


Changes access permissions of the file to which p resolves, as if by POSIX fchmodat.
Symlinks are followed if prms::resolve_symlinks is set.


The effects depend on prms as follows:


* If neither perms::add_perms nor perms::remove_perms is set, file permissions are
set to exactly prms & fs::perms::mask (meaning, every valid bit of prms is
applied)
* If perms::add_perms, the file permissions are set to exactly
status(p).permissions() | (prms & perms::mask) (meaning, any valid bit that is
set in prms, but not in the file's current permissions is added to the file's
permissions)
* If perms::remove_perms is set, the file permissions are set to exactly
status(p).permissions() & ~(prms & perms::mask) (meaning, any valid bit that is
clear in prms, but set in the file's current permissions is cleared in the
file's permissions)
* If both perms::add_perms and perms::remove_perms are set, error occurs


The non-throwing overload has no special action on error.


p - path to examine
prms - permissions to set, add, or remove
ec - out-parameter for error reporting in the non-throwing overload


(none)


The overload that does not take a error_code& parameter throws filesystem_error on
underlying OS API errors, constructed with p as the first argument and the OS error
code as the error code argument. std::bad_alloc may be thrown if memory allocation
fails. The overload taking a error_code& parameter sets it to the OS API error code
if an OS API call fails, and executes ec.clear() if no errors occur. This overload
has
noexcept specification:
noexcept


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)

// Run this code


#include <fstream>
#include <bitset>
#include <iostream>
#include <experimental/filesystem>
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");
}


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


perms identifies file system permissions
(enum)
status determines file attributes
symlink_status determines file attributes, checking the symlink target
(function)

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.