xref: /freebsd/contrib/llvm-project/libcxx/include/__filesystem/perms.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10eae32dcSDimitry Andric // -*- C++ -*-
20eae32dcSDimitry Andric //===----------------------------------------------------------------------===//
30eae32dcSDimitry Andric //
40eae32dcSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50eae32dcSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
60eae32dcSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70eae32dcSDimitry Andric //
80eae32dcSDimitry Andric //===----------------------------------------------------------------------===//
90eae32dcSDimitry Andric 
100eae32dcSDimitry Andric #ifndef _LIBCPP___FILESYSTEM_PERMS_H
110eae32dcSDimitry Andric #define _LIBCPP___FILESYSTEM_PERMS_H
120eae32dcSDimitry Andric 
130eae32dcSDimitry Andric #include <__availability>
140eae32dcSDimitry Andric #include <__config>
150eae32dcSDimitry Andric 
1681ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1781ad6265SDimitry Andric #  pragma GCC system_header
1881ad6265SDimitry Andric #endif
1981ad6265SDimitry Andric 
20*5f757f3fSDimitry Andric #if _LIBCPP_STD_VER >= 17
210eae32dcSDimitry Andric 
220eae32dcSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
230eae32dcSDimitry Andric 
240eae32dcSDimitry Andric // On Windows, these permission bits map to one single readonly flag per
250eae32dcSDimitry Andric // file, and the executable bit is always returned as set. When setting
260eae32dcSDimitry Andric // permissions, as long as the write bit is set for either owner, group or
270eae32dcSDimitry Andric // others, the readonly flag is cleared.
28*5f757f3fSDimitry Andric enum class perms : unsigned {
290eae32dcSDimitry Andric   none = 0,
300eae32dcSDimitry Andric 
310eae32dcSDimitry Andric   owner_read = 0400,
320eae32dcSDimitry Andric   owner_write = 0200,
330eae32dcSDimitry Andric   owner_exec = 0100,
340eae32dcSDimitry Andric   owner_all = 0700,
350eae32dcSDimitry Andric 
360eae32dcSDimitry Andric   group_read = 040,
370eae32dcSDimitry Andric   group_write = 020,
380eae32dcSDimitry Andric   group_exec = 010,
390eae32dcSDimitry Andric   group_all = 070,
400eae32dcSDimitry Andric 
410eae32dcSDimitry Andric   others_read = 04,
420eae32dcSDimitry Andric   others_write = 02,
430eae32dcSDimitry Andric   others_exec = 01,
440eae32dcSDimitry Andric   others_all = 07,
450eae32dcSDimitry Andric 
460eae32dcSDimitry Andric   all = 0777,
470eae32dcSDimitry Andric 
480eae32dcSDimitry Andric   set_uid = 04000,
490eae32dcSDimitry Andric   set_gid = 02000,
500eae32dcSDimitry Andric   sticky_bit = 01000,
510eae32dcSDimitry Andric   mask = 07777,
520eae32dcSDimitry Andric   unknown = 0xFFFF,
530eae32dcSDimitry Andric };
540eae32dcSDimitry Andric 
55*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI
56753f127fSDimitry Andric inline constexpr perms operator&(perms __lhs, perms __rhs) {
57753f127fSDimitry Andric   return static_cast<perms>(static_cast<unsigned>(__lhs) &
58753f127fSDimitry Andric                             static_cast<unsigned>(__rhs));
590eae32dcSDimitry Andric }
600eae32dcSDimitry Andric 
61*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI
62753f127fSDimitry Andric inline constexpr perms operator|(perms __lhs, perms __rhs) {
63753f127fSDimitry Andric   return static_cast<perms>(static_cast<unsigned>(__lhs) |
64753f127fSDimitry Andric                             static_cast<unsigned>(__rhs));
650eae32dcSDimitry Andric }
660eae32dcSDimitry Andric 
67*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI
68753f127fSDimitry Andric inline constexpr perms operator^(perms __lhs, perms __rhs) {
69753f127fSDimitry Andric   return static_cast<perms>(static_cast<unsigned>(__lhs) ^
70753f127fSDimitry Andric                             static_cast<unsigned>(__rhs));
710eae32dcSDimitry Andric }
720eae32dcSDimitry Andric 
73*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI
74753f127fSDimitry Andric inline constexpr perms operator~(perms __lhs) {
75753f127fSDimitry Andric   return static_cast<perms>(~static_cast<unsigned>(__lhs));
760eae32dcSDimitry Andric }
770eae32dcSDimitry Andric 
78*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI
79753f127fSDimitry Andric inline perms& operator&=(perms& __lhs, perms __rhs) { return __lhs = __lhs & __rhs; }
800eae32dcSDimitry Andric 
81*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI
82753f127fSDimitry Andric inline perms& operator|=(perms& __lhs, perms __rhs) { return __lhs = __lhs | __rhs; }
830eae32dcSDimitry Andric 
84*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI
85753f127fSDimitry Andric inline perms& operator^=(perms& __lhs, perms __rhs) { return __lhs = __lhs ^ __rhs; }
860eae32dcSDimitry Andric 
870eae32dcSDimitry Andric _LIBCPP_END_NAMESPACE_FILESYSTEM
880eae32dcSDimitry Andric 
89*5f757f3fSDimitry Andric #endif // _LIBCPP_STD_VER >= 17
900eae32dcSDimitry Andric 
910eae32dcSDimitry Andric #endif // _LIBCPP___FILESYSTEM_PERMS_H
92