xref: /freebsd/contrib/llvm-project/libcxx/include/__filesystem/perms.h (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
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 
16*81ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17*81ad6265SDimitry Andric #  pragma GCC system_header
18*81ad6265SDimitry Andric #endif
19*81ad6265SDimitry 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
580eae32dcSDimitry Andric inline constexpr perms operator&(perms _LHS, perms _RHS) {
590eae32dcSDimitry Andric   return static_cast<perms>(static_cast<unsigned>(_LHS) &
600eae32dcSDimitry Andric                             static_cast<unsigned>(_RHS));
610eae32dcSDimitry Andric }
620eae32dcSDimitry Andric 
630eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY
640eae32dcSDimitry Andric inline constexpr perms operator|(perms _LHS, perms _RHS) {
650eae32dcSDimitry Andric   return static_cast<perms>(static_cast<unsigned>(_LHS) |
660eae32dcSDimitry Andric                             static_cast<unsigned>(_RHS));
670eae32dcSDimitry Andric }
680eae32dcSDimitry Andric 
690eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY
700eae32dcSDimitry Andric inline constexpr perms operator^(perms _LHS, perms _RHS) {
710eae32dcSDimitry Andric   return static_cast<perms>(static_cast<unsigned>(_LHS) ^
720eae32dcSDimitry Andric                             static_cast<unsigned>(_RHS));
730eae32dcSDimitry Andric }
740eae32dcSDimitry Andric 
750eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY
760eae32dcSDimitry Andric inline constexpr perms operator~(perms _LHS) {
770eae32dcSDimitry Andric   return static_cast<perms>(~static_cast<unsigned>(_LHS));
780eae32dcSDimitry Andric }
790eae32dcSDimitry Andric 
800eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY
810eae32dcSDimitry Andric inline perms& operator&=(perms& _LHS, perms _RHS) { return _LHS = _LHS & _RHS; }
820eae32dcSDimitry Andric 
830eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY
840eae32dcSDimitry Andric inline perms& operator|=(perms& _LHS, perms _RHS) { return _LHS = _LHS | _RHS; }
850eae32dcSDimitry Andric 
860eae32dcSDimitry Andric _LIBCPP_INLINE_VISIBILITY
870eae32dcSDimitry 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