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