xref: /freebsd/contrib/llvm-project/libcxx/include/__filesystem/perms.h (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
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 
205f757f3fSDimitry 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.
285f757f3fSDimitry 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*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator&(perms __lhs, perms __rhs) {
56*cb14a3feSDimitry Andric   return static_cast<perms>(static_cast<unsigned>(__lhs) & static_cast<unsigned>(__rhs));
570eae32dcSDimitry Andric }
580eae32dcSDimitry Andric 
59*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator|(perms __lhs, perms __rhs) {
60*cb14a3feSDimitry Andric   return static_cast<perms>(static_cast<unsigned>(__lhs) | static_cast<unsigned>(__rhs));
610eae32dcSDimitry Andric }
620eae32dcSDimitry Andric 
63*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator^(perms __lhs, perms __rhs) {
64*cb14a3feSDimitry Andric   return static_cast<perms>(static_cast<unsigned>(__lhs) ^ static_cast<unsigned>(__rhs));
650eae32dcSDimitry Andric }
660eae32dcSDimitry Andric 
67*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator~(perms __lhs) {
68753f127fSDimitry Andric   return static_cast<perms>(~static_cast<unsigned>(__lhs));
690eae32dcSDimitry Andric }
700eae32dcSDimitry Andric 
71*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline perms& operator&=(perms& __lhs, perms __rhs) { return __lhs = __lhs & __rhs; }
720eae32dcSDimitry Andric 
73*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline perms& operator|=(perms& __lhs, perms __rhs) { return __lhs = __lhs | __rhs; }
740eae32dcSDimitry Andric 
75*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline perms& operator^=(perms& __lhs, perms __rhs) { return __lhs = __lhs ^ __rhs; }
760eae32dcSDimitry Andric 
770eae32dcSDimitry Andric _LIBCPP_END_NAMESPACE_FILESYSTEM
780eae32dcSDimitry Andric 
795f757f3fSDimitry Andric #endif // _LIBCPP_STD_VER >= 17
800eae32dcSDimitry Andric 
810eae32dcSDimitry Andric #endif // _LIBCPP___FILESYSTEM_PERMS_H
82