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 200eae32dcSDimitry Andric #ifndef _LIBCPP_CXX03_LANG 210eae32dcSDimitry Andric 220eae32dcSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM 230eae32dcSDimitry Andric 240eae32dcSDimitry Andric _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH 250eae32dcSDimitry Andric 260eae32dcSDimitry Andric // On Windows, these permission bits map to one single readonly flag per 270eae32dcSDimitry Andric // file, and the executable bit is always returned as set. When setting 280eae32dcSDimitry Andric // permissions, as long as the write bit is set for either owner, group or 290eae32dcSDimitry Andric // others, the readonly flag is cleared. 300eae32dcSDimitry Andric enum class _LIBCPP_ENUM_VIS perms : unsigned { 310eae32dcSDimitry Andric none = 0, 320eae32dcSDimitry Andric 330eae32dcSDimitry Andric owner_read = 0400, 340eae32dcSDimitry Andric owner_write = 0200, 350eae32dcSDimitry Andric owner_exec = 0100, 360eae32dcSDimitry Andric owner_all = 0700, 370eae32dcSDimitry Andric 380eae32dcSDimitry Andric group_read = 040, 390eae32dcSDimitry Andric group_write = 020, 400eae32dcSDimitry Andric group_exec = 010, 410eae32dcSDimitry Andric group_all = 070, 420eae32dcSDimitry Andric 430eae32dcSDimitry Andric others_read = 04, 440eae32dcSDimitry Andric others_write = 02, 450eae32dcSDimitry Andric others_exec = 01, 460eae32dcSDimitry Andric others_all = 07, 470eae32dcSDimitry Andric 480eae32dcSDimitry Andric all = 0777, 490eae32dcSDimitry Andric 500eae32dcSDimitry Andric set_uid = 04000, 510eae32dcSDimitry Andric set_gid = 02000, 520eae32dcSDimitry Andric sticky_bit = 01000, 530eae32dcSDimitry Andric mask = 07777, 540eae32dcSDimitry Andric unknown = 0xFFFF, 550eae32dcSDimitry Andric }; 560eae32dcSDimitry Andric 570eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY 58*753f127fSDimitry Andric inline constexpr perms operator&(perms __lhs, perms __rhs) { 59*753f127fSDimitry Andric return static_cast<perms>(static_cast<unsigned>(__lhs) & 60*753f127fSDimitry Andric static_cast<unsigned>(__rhs)); 610eae32dcSDimitry Andric } 620eae32dcSDimitry Andric 630eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY 64*753f127fSDimitry Andric inline constexpr perms operator|(perms __lhs, perms __rhs) { 65*753f127fSDimitry Andric return static_cast<perms>(static_cast<unsigned>(__lhs) | 66*753f127fSDimitry Andric static_cast<unsigned>(__rhs)); 670eae32dcSDimitry Andric } 680eae32dcSDimitry Andric 690eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY 70*753f127fSDimitry Andric inline constexpr perms operator^(perms __lhs, perms __rhs) { 71*753f127fSDimitry Andric return static_cast<perms>(static_cast<unsigned>(__lhs) ^ 72*753f127fSDimitry Andric static_cast<unsigned>(__rhs)); 730eae32dcSDimitry Andric } 740eae32dcSDimitry Andric 750eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY 76*753f127fSDimitry Andric inline constexpr perms operator~(perms __lhs) { 77*753f127fSDimitry Andric return static_cast<perms>(~static_cast<unsigned>(__lhs)); 780eae32dcSDimitry Andric } 790eae32dcSDimitry Andric 800eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY 81*753f127fSDimitry Andric inline perms& operator&=(perms& __lhs, perms __rhs) { return __lhs = __lhs & __rhs; } 820eae32dcSDimitry Andric 830eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY 84*753f127fSDimitry Andric inline perms& operator|=(perms& __lhs, perms __rhs) { return __lhs = __lhs | __rhs; } 850eae32dcSDimitry Andric 860eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY 87*753f127fSDimitry Andric inline perms& operator^=(perms& __lhs, perms __rhs) { return __lhs = __lhs ^ __rhs; } 880eae32dcSDimitry Andric 890eae32dcSDimitry Andric _LIBCPP_AVAILABILITY_FILESYSTEM_POP 900eae32dcSDimitry Andric 910eae32dcSDimitry Andric _LIBCPP_END_NAMESPACE_FILESYSTEM 920eae32dcSDimitry Andric 930eae32dcSDimitry Andric #endif // _LIBCPP_CXX03_LANG 940eae32dcSDimitry Andric 950eae32dcSDimitry Andric #endif // _LIBCPP___FILESYSTEM_PERMS_H 96