aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-10-23 19:59:03 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-10-23 19:59:03 +0300
commit0843ecaee7c53dea868f866811559416533d49cc (patch)
tree2baf3750ef215b5ffe5343e446ac3187f7a01cd4
parentshmem_tests: notify_all outside of lock (diff)
downloadwinapi-common-0843ecaee7c53dea868f866811559416533d49cc.tar.gz
winapi-common-0843ecaee7c53dea868f866811559416533d49cc.zip
Handle: add static is_invalid() method
Diffstat (limited to '')
-rw-r--r--include/winapi/handle.hpp1
-rw-r--r--src/handle.cpp12
2 files changed, 7 insertions, 6 deletions
diff --git a/include/winapi/handle.hpp b/include/winapi/handle.hpp
index f6f4c11..536de26 100644
--- a/include/winapi/handle.hpp
+++ b/include/winapi/handle.hpp
@@ -31,6 +31,7 @@ public:
explicit operator HANDLE() const { return m_impl.get(); }
bool is_invalid() const;
+ static bool is_invalid(HANDLE);
void close();
diff --git a/src/handle.cpp b/src/handle.cpp
index c94cb16..fa3d8c0 100644
--- a/src/handle.cpp
+++ b/src/handle.cpp
@@ -27,10 +27,6 @@ std::runtime_error write_file_incomplete(std::size_t expected, std::size_t actua
return std::runtime_error{oss.str()};
}
-bool is_invalid_handle(HANDLE handle) {
- return handle == NULL || handle == INVALID_HANDLE_VALUE;
-}
-
bool is_std_handle(HANDLE handle) {
return handle == ::GetStdHandle(STD_INPUT_HANDLE) ||
handle == ::GetStdHandle(STD_OUTPUT_HANDLE) ||
@@ -56,7 +52,11 @@ void Handle::swap(Handle& other) BOOST_NOEXCEPT_OR_NOTHROW {
}
bool Handle::is_invalid() const {
- return !m_impl || is_invalid_handle(m_impl.get());
+ return !m_impl || is_invalid(m_impl.get());
+}
+
+bool Handle::is_invalid(HANDLE handle) {
+ return handle == NULL || handle == INVALID_HANDLE_VALUE;
}
void Handle::close() {
@@ -143,7 +143,7 @@ void Handle::inherit(bool yes) const {
}
void Handle::Close::operator()(HANDLE impl) const {
- if (is_invalid_handle(impl) || is_std_handle(impl))
+ if (is_invalid(impl) || is_std_handle(impl))
return;
const auto ret = ::CloseHandle(impl);
assert(ret);