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 <__config> 140eae32dcSDimitry Andric 1581ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1681ad6265SDimitry Andric # pragma GCC system_header 1781ad6265SDimitry Andric #endif 1881ad6265SDimitry Andric 195f757f3fSDimitry Andric #if _LIBCPP_STD_VER >= 17 200eae32dcSDimitry Andric 210eae32dcSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM 220eae32dcSDimitry Andric 230eae32dcSDimitry Andric // On Windows, these permission bits map to one single readonly flag per 240eae32dcSDimitry Andric // file, and the executable bit is always returned as set. When setting 250eae32dcSDimitry Andric // permissions, as long as the write bit is set for either owner, group or 260eae32dcSDimitry Andric // others, the readonly flag is cleared. 275f757f3fSDimitry Andric enum class perms : unsigned { 280eae32dcSDimitry Andric none = 0, 290eae32dcSDimitry Andric 300eae32dcSDimitry Andric owner_read = 0400, 310eae32dcSDimitry Andric owner_write = 0200, 320eae32dcSDimitry Andric owner_exec = 0100, 330eae32dcSDimitry Andric owner_all = 0700, 340eae32dcSDimitry Andric 350eae32dcSDimitry Andric group_read = 040, 360eae32dcSDimitry Andric group_write = 020, 370eae32dcSDimitry Andric group_exec = 010, 380eae32dcSDimitry Andric group_all = 070, 390eae32dcSDimitry Andric 400eae32dcSDimitry Andric others_read = 04, 410eae32dcSDimitry Andric others_write = 02, 420eae32dcSDimitry Andric others_exec = 01, 430eae32dcSDimitry Andric others_all = 07, 440eae32dcSDimitry Andric 450eae32dcSDimitry Andric all = 0777, 460eae32dcSDimitry Andric 470eae32dcSDimitry Andric set_uid = 04000, 480eae32dcSDimitry Andric set_gid = 02000, 490eae32dcSDimitry Andric sticky_bit = 01000, 500eae32dcSDimitry Andric mask = 07777, 510eae32dcSDimitry Andric unknown = 0xFFFF, 520eae32dcSDimitry Andric }; 530eae32dcSDimitry Andric 54*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator&(perms __lhs, perms __rhs) { 55*cb14a3feSDimitry Andric return static_cast<perms>(static_cast<unsigned>(__lhs) & static_cast<unsigned>(__rhs)); 560eae32dcSDimitry Andric } 570eae32dcSDimitry Andric 58*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator|(perms __lhs, perms __rhs) { 59*cb14a3feSDimitry Andric return static_cast<perms>(static_cast<unsigned>(__lhs) | static_cast<unsigned>(__rhs)); 600eae32dcSDimitry Andric } 610eae32dcSDimitry Andric 62*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator^(perms __lhs, perms __rhs) { 63*cb14a3feSDimitry Andric return static_cast<perms>(static_cast<unsigned>(__lhs) ^ static_cast<unsigned>(__rhs)); 640eae32dcSDimitry Andric } 650eae32dcSDimitry Andric 66*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator~(perms __lhs) { 67753f127fSDimitry Andric return static_cast<perms>(~static_cast<unsigned>(__lhs)); 680eae32dcSDimitry Andric } 690eae32dcSDimitry Andric 70*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline perms& operator&=(perms& __lhs, perms __rhs) { return __lhs = __lhs & __rhs; } 710eae32dcSDimitry Andric 72*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline perms& operator|=(perms& __lhs, perms __rhs) { return __lhs = __lhs | __rhs; } 730eae32dcSDimitry Andric 74*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline perms& operator^=(perms& __lhs, perms __rhs) { return __lhs = __lhs ^ __rhs; } 750eae32dcSDimitry Andric 760eae32dcSDimitry Andric _LIBCPP_END_NAMESPACE_FILESYSTEM 770eae32dcSDimitry Andric 785f757f3fSDimitry Andric #endif // _LIBCPP_STD_VER >= 17 790eae32dcSDimitry Andric 800eae32dcSDimitry Andric #endif // _LIBCPP___FILESYSTEM_PERMS_H 81