-
Notifications
You must be signed in to change notification settings - Fork 3
/
myperms.hpp
88 lines (76 loc) · 2 KB
/
myperms.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// Created by koncord on 12.11.17.
//
// copied from experimental/bits/fs_fwd.h
#pragma once
#include <type_traits>
namespace myfs
{
enum class perms : unsigned
{
none = 0,
owner_read = 0400,
owner_write = 0200,
owner_exec = 0100,
owner_all = 0700,
group_read = 040,
group_write = 020,
group_exec = 010,
group_all = 070,
others_read = 04,
others_write = 02,
others_exec = 01,
others_all = 07,
all = 0777,
set_uid = 04000,
set_gid = 02000,
sticky_bit = 01000,
mask = 07777,
unknown = 0xFFFF,
add_perms = 0x10000,
remove_perms = 0x20000,
symlink_nofollow = 0x40000
};
constexpr perms
operator&(perms __x, perms __y) noexcept
{
using __utype = typename std::underlying_type<perms>::type;
return static_cast<perms>(
static_cast<__utype>(__x) & static_cast<__utype>(__y));
}
constexpr perms
operator|(perms __x, perms __y) noexcept
{
using __utype = typename std::underlying_type<perms>::type;
return static_cast<perms>(
static_cast<__utype>(__x) | static_cast<__utype>(__y));
}
constexpr perms
operator^(perms __x, perms __y) noexcept
{
using __utype = typename std::underlying_type<perms>::type;
return static_cast<perms>(
static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
}
constexpr perms
operator~(perms __x) noexcept
{
using __utype = typename std::underlying_type<perms>::type;
return static_cast<perms>(~static_cast<__utype>(__x));
}
inline perms &
operator&=(perms &__x, perms __y) noexcept
{
return __x = __x & __y;
}
inline perms &
operator|=(perms &__x, perms __y) noexcept
{
return __x = __x | __y;
}
inline perms &
operator^=(perms &__x, perms __y) noexcept
{
return __x = __x ^ __y;
}
}