Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::filesystem::perms

      From cppreference.com
      <cpp‎ |experimental‎ |fs
       
       
       
      Filesystem library
      Classes
      Functions
      File types
       
      Defined in header<experimental/filesystem>
      enumclass perms;
      (filesystem TS)

      This type represents file access permissions.perms satisfies the requirements ofBitmaskType (which means the bitwise operatorsoperator&,operator|,operator^,operator~,operator&=,operator|=, andoperator^= are defined for this type).

      Access permissions modelPOSIX permission bits, and any individual file permissions (as reported bystatus) are a combination of some of the following bits:

      Contents

      [edit]Member constants

      Member constantValue (octal)POSIX equivalentMeaning
      none0No permission bits are set
      owner_read0400S_IRUSRFile owner has read permission
      owner_write0200S_IWUSRFile owner has write permission
      owner_exec0100S_IXUSRFile owner has execute/search permission
      owner_all0700S_IRWXUFile owner has read, write, and execute/search permissions

      Equivalent toowner_read| owner_write| owner_exec

      group_read040S_IRGRPThe file's user group has read permission
      group_write020S_IWGRPThe file's user group has write permission
      group_exec010S_IXGRPThe file's user group has execute/search permission
      group_all070S_IRWXGThe file's user group has read, write, and execute/search permissions

      Equivalent togroup_read| group_write| group_exec

      others_read04S_IROTHOther users have read permission
      others_write02S_IWOTHOther users have write permission
      others_exec01S_IXOTHOther users have execute/search permission
      others_all07S_IRWXOOther users have read, write, and execute/search permissions

      Equivalent toothers_read| others_write| others_exec

      all0777All users have read, write, and execute/search permissions

      Equivalent toowner_all| group_all| others_all

      set_uid04000S_ISUIDSet user ID to file owner user ID on execution
      set_gid02000S_ISGIDSet group ID to file's user group ID on execution
      sticky_bit01000S_ISVTXImplementation-defined meaning, but POSIX XSI specifies that when set on a directory, only file owners may delete files even if the directory is writeable to others (used with/tmp)
      mask07777All valid permission bits

      Equivalent toall| set_uid| set_gid| sticky_bit

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

      Member constantValue (hex)Meaning
      unknown0xFFFFUnknown permissions (e.g. whenfile_status is created without permissions)
      add_perms0x10000Control bit that instructspermissions to add, but not clear permission bits
      remove_perms0x20000Control bit that instructspermissions to clear, but not add permission bits
      resolve_symlinks0x40000Control bit that instructspermissions to resolve symlinks

      [edit]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).

      [edit]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--

      [edit]See also

      determines file attributes
      determines file attributes, checking the symlink target
      (function)[edit]
      modifies file access permissions
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/fs/perms&oldid=158868"

      [8]ページ先頭

      ©2009-2025 Movatter.jp