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

FreeBSD Manual Pages

  
 
  

home | help
std::experi...stem::perms(3)  C++ Standard Libary std::experi...stem::perms(3)

NAME
       std::experimental::filesystem::perms    -   std::experimental::filesys-
       tem::perms

Synopsis
	  Defined in header <experimental/filesystem>
	  enum class perms;			       (filesystem TS)

	  This type represents file access permissions.	 perms	satisfies  the
       requirements of
	  BitmaskType (which means the bitwise operators operator&, operator|,
       operator^,
	  operator~,  operator&=,  operator|=,	and operator^= are defined for
       this type).

	  Access permissions model POSIX permission bits, and  any  individual
       file permissions
	  (as  reported	 by status) are	a combination of some of the following
       bits:

Member constants
	  Member constant Value	(octal)	POSIX equivalent		 Mean-
       ing
	  none		   0				   No  permission bits
       are set
	  owner_read	  0400		S_IRUSR		 File owner  has  read
       permission
	  owner_write	   0200		 S_IWUSR	  File owner has write
       permission
	  owner_exec	  0100		S_IXUSR		 File owner  has  exe-
       cute/search
							 permission
							 File  owner has read,
       write, and
							 execute/search	  per-
       missions
	  owner_all	  0700		S_IRWXU
							 Equivalent	    to
       owner_read |
							 owner_write	     |
       owner_exec
	  group_read	  040		S_IRGRP		 The file's user group
       has read
							 permission
	  group_write	  020		S_IWGRP		 The file's user group
       has write
							 permission
	  group_exec	  010		S_IXGRP		 The file's user group
       has
							 execute/search	  per-
       mission
							 The file's user group
       has read,
							 write,	   and	  exe-
       cute/search permissions
	  group_all	  070		S_IRWXG
							 Equivalent	    to
       group_read |
							 group_write	     |
       group_exec
	  others_read	  04		S_IROTH		 Other users have read
       permission
	  others_write	   02		  S_IWOTH	    Other  users  have
       write permission
	  others_exec	  01		S_IXOTH		 Other users have exe-
       cute/search
							 permission
							 Other	 users	  have
       read, write, and
							 execute/search	  per-
       missions
	  others_all	  07		S_IRWXO
							 Equivalent  to	  oth-
       ers_read	|
							 others_write  |  oth-
       ers_exec
							 All users have	 read,
       write, and
							 execute/search	  per-
       missions
	  all		  0777
							 Equivalent	    to
       owner_all | group_all |
							 others_all
	  set_uid	   04000	  S_ISUID	   Set user ID to file
       owner user ID on
							 execution
	  set_gid	   02000	  S_ISGID	    Set	 group	ID  to
       file's user group ID
							 on execution
							 Implementation-de-
       fined meaning, but
							 POSIX	XSI  specifies
       that when set on
	  sticky_bit	  01000		 S_ISVTX	   a  directory,  only
       file owners may
							 delete	 files even if
       the directory is
							 writeable  to	others
       (used with /tmp)
							 All  valid permission
       bits
	  mask		  07777
							 Equivalent to	all  |
       set_uid | set_gid
							 | sticky_bit

	  Additionally,	 the  following	 constants  of	this type are defined,
       which do	not
	  represent permissions:

	  Member constant  Value (hex)			       Meaning
	  unknown	    0xFFFF	  Unknown   permissions	  (e.g.	  when
       file_status is created
				       without permissions)
	  add_perms	    0x10000	Control	bit that instructs permissions
       to add, but not
				       clear permission	bits
	  remove_perms	   0x20000     Control bit that	instructs  permissions
       to clear, but
				       not add permission bits
	  resolve_symlinks  0x40000	Control	bit that instructs permissions
       to resolve
				       symlinks

Notes
	  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).

Example
       // Run this code

	#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--

See also
	  status	 determines file attributes
	  symlink_status determines file attributes, checking the symlink tar-
       get
			 (function)
	  permissions	 modifies file access permissions
			 (function)

Category:
	    * Noindexed	pages

http://cppreference.com		  2024.06.10	  std::experi...stem::perms(3)

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

home | help