perms.h 2.5 KB

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