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 _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
25 
26 // On Windows, these permission bits map to one single readonly flag per
27 // file, and the executable bit is always returned as set. When setting
28 // permissions, as long as the write bit is set for either owner, group or
29 // others, the readonly flag is cleared.
30 enum class _LIBCPP_ENUM_VIS perms : unsigned {
31   none = 0,
32 
33   owner_read = 0400,
34   owner_write = 0200,
35   owner_exec = 0100,
36   owner_all = 0700,
37 
38   group_read = 040,
39   group_write = 020,
40   group_exec = 010,
41   group_all = 070,
42 
43   others_read = 04,
44   others_write = 02,
45   others_exec = 01,
46   others_all = 07,
47 
48   all = 0777,
49 
50   set_uid = 04000,
51   set_gid = 02000,
52   sticky_bit = 01000,
53   mask = 07777,
54   unknown = 0xFFFF,
55 };
56 
57 _LIBCPP_INLINE_VISIBILITY
58 inline constexpr perms operator&(perms __lhs, perms __rhs) {
59   return static_cast<perms>(static_cast<unsigned>(__lhs) &
60                             static_cast<unsigned>(__rhs));
61 }
62 
63 _LIBCPP_INLINE_VISIBILITY
64 inline constexpr perms operator|(perms __lhs, perms __rhs) {
65   return static_cast<perms>(static_cast<unsigned>(__lhs) |
66                             static_cast<unsigned>(__rhs));
67 }
68 
69 _LIBCPP_INLINE_VISIBILITY
70 inline constexpr perms operator^(perms __lhs, perms __rhs) {
71   return static_cast<perms>(static_cast<unsigned>(__lhs) ^
72                             static_cast<unsigned>(__rhs));
73 }
74 
75 _LIBCPP_INLINE_VISIBILITY
76 inline constexpr perms operator~(perms __lhs) {
77   return static_cast<perms>(~static_cast<unsigned>(__lhs));
78 }
79 
80 _LIBCPP_INLINE_VISIBILITY
81 inline perms& operator&=(perms& __lhs, perms __rhs) { return __lhs = __lhs & __rhs; }
82 
83 _LIBCPP_INLINE_VISIBILITY
84 inline perms& operator|=(perms& __lhs, perms __rhs) { return __lhs = __lhs | __rhs; }
85 
86 _LIBCPP_INLINE_VISIBILITY
87 inline perms& operator^=(perms& __lhs, perms __rhs) { return __lhs = __lhs ^ __rhs; }
88 
89 _LIBCPP_AVAILABILITY_FILESYSTEM_POP
90 
91 _LIBCPP_END_NAMESPACE_FILESYSTEM
92 
93 #endif // _LIBCPP_CXX03_LANG
94 
95 #endif // _LIBCPP___FILESYSTEM_PERMS_H
96