perms.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___FILESYSTEM_PERMS_H
  10. #define _LIBCPP___FILESYSTEM_PERMS_H
  11. #include <__config>
  12. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  13. # pragma GCC system_header
  14. #endif
  15. #if _LIBCPP_STD_VER >= 17
  16. _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
  17. // On Windows, these permission bits map to one single readonly flag per
  18. // file, and the executable bit is always returned as set. When setting
  19. // permissions, as long as the write bit is set for either owner, group or
  20. // others, the readonly flag is cleared.
  21. enum class perms : unsigned {
  22. none = 0,
  23. owner_read = 0400,
  24. owner_write = 0200,
  25. owner_exec = 0100,
  26. owner_all = 0700,
  27. group_read = 040,
  28. group_write = 020,
  29. group_exec = 010,
  30. group_all = 070,
  31. others_read = 04,
  32. others_write = 02,
  33. others_exec = 01,
  34. others_all = 07,
  35. all = 0777,
  36. set_uid = 04000,
  37. set_gid = 02000,
  38. sticky_bit = 01000,
  39. mask = 07777,
  40. unknown = 0xFFFF,
  41. };
  42. _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator&(perms __lhs, perms __rhs) {
  43. return static_cast<perms>(static_cast<unsigned>(__lhs) & static_cast<unsigned>(__rhs));
  44. }
  45. _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator|(perms __lhs, perms __rhs) {
  46. return static_cast<perms>(static_cast<unsigned>(__lhs) | static_cast<unsigned>(__rhs));
  47. }
  48. _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator^(perms __lhs, perms __rhs) {
  49. return static_cast<perms>(static_cast<unsigned>(__lhs) ^ static_cast<unsigned>(__rhs));
  50. }
  51. _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator~(perms __lhs) {
  52. return static_cast<perms>(~static_cast<unsigned>(__lhs));
  53. }
  54. _LIBCPP_HIDE_FROM_ABI inline perms& operator&=(perms& __lhs, perms __rhs) { return __lhs = __lhs & __rhs; }
  55. _LIBCPP_HIDE_FROM_ABI inline perms& operator|=(perms& __lhs, perms __rhs) { return __lhs = __lhs | __rhs; }
  56. _LIBCPP_HIDE_FROM_ABI inline perms& operator^=(perms& __lhs, perms __rhs) { return __lhs = __lhs ^ __rhs; }
  57. _LIBCPP_END_NAMESPACE_FILESYSTEM
  58. #endif // _LIBCPP_STD_VER >= 17
  59. #endif // _LIBCPP___FILESYSTEM_PERMS_H