| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
| Classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <experimental/filesystem> | ||
void permissions(const path& p, perms prms); void permissions(const path& p, perms prms, error_code& ec); | (filesystem TS) | |
Changes access permissions of the file to whichp resolves, as if by POSIXfchmodat. Symlinks are followed ifprms::resolve_symlinks is set.
The effects depend onprms as follows:
The non-throwing overload has no special action on error.
Contents |
| p | - | path to examine |
| prms | - | permissions to set, add, or remove |
| ec | - | out-parameter for error reporting in the non-throwing overload |
(none)
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).
#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--
| identifies file system permissions (enum)[edit] | |
| determines file attributes determines file attributes, checking the symlink target (function)[edit] |