1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___FILESYSTEM_PERMS_H 11 #define _LIBCPP___FILESYSTEM_PERMS_H 12 13 #include <__availability> 14 #include <__config> 15 16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17 # pragma GCC system_header 18 #endif 19 20 #if _LIBCPP_STD_VER >= 17 21 22 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM 23 24 // On Windows, these permission bits map to one single readonly flag per 25 // file, and the executable bit is always returned as set. When setting 26 // permissions, as long as the write bit is set for either owner, group or 27 // others, the readonly flag is cleared. 28 enum class perms : unsigned { 29 none = 0, 30 31 owner_read = 0400, 32 owner_write = 0200, 33 owner_exec = 0100, 34 owner_all = 0700, 35 36 group_read = 040, 37 group_write = 020, 38 group_exec = 010, 39 group_all = 070, 40 41 others_read = 04, 42 others_write = 02, 43 others_exec = 01, 44 others_all = 07, 45 46 all = 0777, 47 48 set_uid = 04000, 49 set_gid = 02000, 50 sticky_bit = 01000, 51 mask = 07777, 52 unknown = 0xFFFF, 53 }; 54 55 _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator&(perms __lhs, perms __rhs) { 56 return static_cast<perms>(static_cast<unsigned>(__lhs) & static_cast<unsigned>(__rhs)); 57 } 58 59 _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator|(perms __lhs, perms __rhs) { 60 return static_cast<perms>(static_cast<unsigned>(__lhs) | static_cast<unsigned>(__rhs)); 61 } 62 63 _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator^(perms __lhs, perms __rhs) { 64 return static_cast<perms>(static_cast<unsigned>(__lhs) ^ static_cast<unsigned>(__rhs)); 65 } 66 67 _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator~(perms __lhs) { 68 return static_cast<perms>(~static_cast<unsigned>(__lhs)); 69 } 70 71 _LIBCPP_HIDE_FROM_ABI inline perms& operator&=(perms& __lhs, perms __rhs) { return __lhs = __lhs & __rhs; } 72 73 _LIBCPP_HIDE_FROM_ABI inline perms& operator|=(perms& __lhs, perms __rhs) { return __lhs = __lhs | __rhs; } 74 75 _LIBCPP_HIDE_FROM_ABI inline perms& operator^=(perms& __lhs, perms __rhs) { return __lhs = __lhs ^ __rhs; } 76 77 _LIBCPP_END_NAMESPACE_FILESYSTEM 78 79 #endif // _LIBCPP_STD_VER >= 17 80 81 #endif // _LIBCPP___FILESYSTEM_PERMS_H 82