aboutsummaryrefslogtreecommitdiff
path: root/src/base/platform/win/Base.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/platform/win/Base.cpp')
-rw-r--r--src/base/platform/win/Base.cpp45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/base/platform/win/Base.cpp b/src/base/platform/win/Base.cpp
index 5edf9779..0aae6466 100644
--- a/src/base/platform/win/Base.cpp
+++ b/src/base/platform/win/Base.cpp
@@ -1,37 +1,38 @@
#include "cru/base/platform/win/Base.h"
#include <format>
-#include <optional>
namespace cru::platform::win {
-inline std::string HResultMakeMessage(HRESULT h_result,
- std::optional<std::string_view> message) {
- if (message.has_value())
- return std::format("HRESULT: {}. Message: {}", h_result, *message);
- else
- return std::format("HRESULT: {}.", h_result);
-}
-
-HResultError::HResultError(HRESULT h_result)
- : Exception(HResultMakeMessage(h_result, std::nullopt)),
- h_result_(h_result) {}
-
HResultError::HResultError(HRESULT h_result,
std::string_view additional_message)
- : Exception(HResultMakeMessage(h_result, additional_message)),
- h_result_(h_result) {}
-
-inline std::string Win32MakeMessage(DWORD error_code,
- std::string_view message) {
- return std::format("Last error code: {}.\nMessage: {}\n", error_code,
- message);
+ : Exception(std::format("HRESULT is {}.", h_result)), h_result_(h_result) {
+ AppendMessage(additional_message);
}
Win32Error::Win32Error(std::string_view message)
: Win32Error(::GetLastError(), message) {}
Win32Error::Win32Error(DWORD error_code, std::string_view message)
- : Exception(Win32MakeMessage(error_code, message)),
- error_code_(error_code) {}
+ : Exception(std::format("Last Windows error code is {}.", error_code)),
+ error_code_(error_code) {
+ AppendMessage(message);
+}
+
+UniDirectionalWin32PipeResult OpenUniDirectionalPipe(Win32PipeFlag flag) {
+ HANDLE read, write;
+ CheckWinReturn(::CreatePipe(&read, &write, nullptr, 0));
+
+ if (flag.Has(Win32PipeFlags::ReadInheritable)) {
+ CheckWinReturn(
+ ::SetHandleInformation(read, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT));
+ }
+
+ if (flag.Has(Win32PipeFlags::WriteInheritable)) {
+ CheckWinReturn(::SetHandleInformation(write, HANDLE_FLAG_INHERIT,
+ HANDLE_FLAG_INHERIT));
+ }
+
+ return {Win32Handle(read, true), Win32Handle(write, true)};
+}
} // namespace cru::platform::win