perms.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #if _LIBCPP_STD_VER >= 17
  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_HIDE_FROM_ABI inline constexpr perms operator&(perms __lhs, perms __rhs) {
  44. return static_cast<perms>(static_cast<unsigned>(__lhs) & static_cast<unsigned>(__rhs));
  45. }
  46. _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator|(perms __lhs, perms __rhs) {
  47. return static_cast<perms>(static_cast<unsigned>(__lhs) | static_cast<unsigned>(__rhs));
  48. }
  49. _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator^(perms __lhs, perms __rhs) {
  50. return static_cast<perms>(static_cast<unsigned>(__lhs) ^ static_cast<unsigned>(__rhs));
  51. }
  52. _LIBCPP_HIDE_FROM_ABI inline constexpr perms operator~(perms __lhs) {
  53. return static_cast<perms>(~static_cast<unsigned>(__lhs));
  54. }
  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_HIDE_FROM_ABI inline perms& operator^=(perms& __lhs, perms __rhs) { return __lhs = __lhs ^ __rhs; }
  58. _LIBCPP_END_NAMESPACE_FILESYSTEM
  59. #endif // _LIBCPP_STD_VER >= 17
  60. #endif // _LIBCPP___FILESYSTEM_PERMS_H