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