Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::filesy...:permissions(3) C++ Standard Libarystd::filesy...:permissions(3)

NAME
       std::filesystem::file_status::permissions  - std::filesystem::file_sta-
       tus::permissions

Synopsis
	  std::filesystem::perms permissions() const noexcept;	    (1)	(since
       C++17)
	  void permissions( std::filesystem::perms perm	) noexcept; (2)	(since
       C++17)

	  Accesses the file permissions	information.

	  1) Returns file permissions information.
	  2) Sets file permissions to perm.

Parameters
	  perm - file permissions to set to

Return value
	  1) File permissions information.
	  2) (none)

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::filesys-
       tem::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--

http://cppreference.com		  2024.06.10	 std::filesy...:permissions(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::filesystem::file_status::permissions&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help