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 #ifndef _LIBCPP_CXX03_LANG
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 _LIBCPP_ENUM_VIS 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_INLINE_VISIBILITY
56 inline constexpr perms operator&(perms __lhs, perms __rhs) {
57   return static_cast<perms>(static_cast<unsigned>(__lhs) &
58                             static_cast<unsigned>(__rhs));
59 }
60 
61 _LIBCPP_INLINE_VISIBILITY
62 inline constexpr perms operator|(perms __lhs, perms __rhs) {
63   return static_cast<perms>(static_cast<unsigned>(__lhs) |
64                             static_cast<unsigned>(__rhs));
65 }
66 
67 _LIBCPP_INLINE_VISIBILITY
68 inline constexpr perms operator^(perms __lhs, perms __rhs) {
69   return static_cast<perms>(static_cast<unsigned>(__lhs) ^
70                             static_cast<unsigned>(__rhs));
71 }
72 
73 _LIBCPP_INLINE_VISIBILITY
74 inline constexpr perms operator~(perms __lhs) {
75   return static_cast<perms>(~static_cast<unsigned>(__lhs));
76 }
77 
78 _LIBCPP_INLINE_VISIBILITY
79 inline perms& operator&=(perms& __lhs, perms __rhs) { return __lhs = __lhs & __rhs; }
80 
81 _LIBCPP_INLINE_VISIBILITY
82 inline perms& operator|=(perms& __lhs, perms __rhs) { return __lhs = __lhs | __rhs; }
83 
84 _LIBCPP_INLINE_VISIBILITY
85 inline perms& operator^=(perms& __lhs, perms __rhs) { return __lhs = __lhs ^ __rhs; }
86 
87 _LIBCPP_END_NAMESPACE_FILESYSTEM
88 
89 #endif // _LIBCPP_CXX03_LANG
90 
91 #endif // _LIBCPP___FILESYSTEM_PERMS_H
92