perms.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <__availability>
  12. #include <__config>
  13. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  14. # pragma GCC system_header
  15. #endif
  16. #ifndef _LIBCPP_CXX03_LANG
  17. _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
  18. // On Windows, these permission bits map to one single readonly flag per
  19. // file, and the executable bit is always returned as set. When setting
  20. // permissions, as long as the write bit is set for either owner, group or
  21. // others, the readonly flag is cleared.
  22. enum class perms : unsigned {
  23. none = 0,
  24. owner_read = 0400,
  25. owner_write = 0200,
  26. owner_exec = 0100,
  27. owner_all = 0700,
  28. group_read = 040,
  29. group_write = 020,
  30. group_exec = 010,
  31. group_all = 070,
  32. others_read = 04,
  33. others_write = 02,
  34. others_exec = 01,
  35. others_all = 07,
  36. all = 0777,
  37. set_uid = 04000,
  38. set_gid = 02000,
  39. sticky_bit = 01000,
  40. mask = 07777,
  41. unknown = 0xFFFF,
  42. };
  43. _LIBCPP_INLINE_VISIBILITY
  44. inline constexpr perms operator&(perms __lhs, perms __rhs) {
  45. return static_cast<perms>(static_cast<unsigned>(__lhs) &
  46. static_cast<unsigned>(__rhs));
  47. }
  48. _LIBCPP_INLINE_VISIBILITY
  49. inline constexpr perms operator|(perms __lhs, perms __rhs) {
  50. return static_cast<perms>(static_cast<unsigned>(__lhs) |
  51. static_cast<unsigned>(__rhs));
  52. }
  53. _LIBCPP_INLINE_VISIBILITY
  54. inline constexpr perms operator^(perms __lhs, perms __rhs) {
  55. return static_cast<perms>(static_cast<unsigned>(__lhs) ^
  56. static_cast<unsigned>(__rhs));
  57. }
  58. _LIBCPP_INLINE_VISIBILITY
  59. inline constexpr perms operator~(perms __lhs) {
  60. return static_cast<perms>(~static_cast<unsigned>(__lhs));
  61. }
  62. _LIBCPP_INLINE_VISIBILITY
  63. inline perms& operator&=(perms& __lhs, perms __rhs) { return __lhs = __lhs & __rhs; }
  64. _LIBCPP_INLINE_VISIBILITY
  65. inline perms& operator|=(perms& __lhs, perms __rhs) { return __lhs = __lhs | __rhs; }
  66. _LIBCPP_INLINE_VISIBILITY
  67. inline perms& operator^=(perms& __lhs, perms __rhs) { return __lhs = __lhs ^ __rhs; }
  68. _LIBCPP_END_NAMESPACE_FILESYSTEM
  69. #endif // _LIBCPP_CXX03_LANG
  70. #endif // _LIBCPP___FILESYSTEM_PERMS_H