From 924f4b472712d0cfc55b81dcb3eaed3f8a478288 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Thu, 19 Feb 2026 19:23:20 +0800 Subject: fix windows build. --- src/base/platform/win/Base.cpp | 2 +- src/base/platform/win/Stream.cpp | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/base/platform/win/Base.cpp b/src/base/platform/win/Base.cpp index 0aae6466..43357c35 100644 --- a/src/base/platform/win/Base.cpp +++ b/src/base/platform/win/Base.cpp @@ -33,6 +33,6 @@ UniDirectionalWin32PipeResult OpenUniDirectionalPipe(Win32PipeFlag flag) { HANDLE_FLAG_INHERIT)); } - return {Win32Handle(read, true), Win32Handle(write, true)}; + return {Win32Handle(read), Win32Handle(write)}; } } // namespace cru::platform::win diff --git a/src/base/platform/win/Stream.cpp b/src/base/platform/win/Stream.cpp index 72466905..10b80a16 100644 --- a/src/base/platform/win/Stream.cpp +++ b/src/base/platform/win/Stream.cpp @@ -42,9 +42,9 @@ HANDLE OpenHandle(std::string_view path, OpenFileFlag flags) { IStream* stream; - auto handle = - ::CreateFileW(cru::string::ToUtf16WString(path).c_str(), access, 0, nullptr, - creation_disposition, FILE_ATTRIBUTE_NORMAL, nullptr); + auto handle = ::CreateFileW(cru::string::ToUtf16WString(path).c_str(), access, + 0, nullptr, creation_disposition, + FILE_ATTRIBUTE_NORMAL, nullptr); if (handle == INVALID_HANDLE_VALUE) { throw Win32Error("Failed to call CreateFileW."); @@ -68,13 +68,14 @@ Win32HandleStream::Win32HandleStream(std::string_view path, OpenFileFlag flags) Win32HandleStream::Win32HandleStream(HANDLE handle, bool auto_close, bool can_seek, bool can_read, bool can_write) - : Win32HandleStream(Win32Handle(handle, auto_close), can_seek, can_read, - can_write) {} + : Stream(SupportedOperations(can_seek, can_read, can_write)), + handle_(handle), + auto_close_(auto_close) {} Win32HandleStream::Win32HandleStream(Win32Handle&& handle, bool can_seek, bool can_read, bool can_write) - : Stream(SupportedOperations(can_seek, can_read, can_write)), - handle_(std::move(handle)) {} + : Win32HandleStream(handle.Release(), true, can_seek, can_read, can_write) { +} Win32HandleStream::~Win32HandleStream() { DoClose(); } @@ -92,14 +93,14 @@ Index Win32HandleStream::DoSeek(Index offset, SeekOrigin origin) { LARGE_INTEGER n_offset, new_pos; n_offset.QuadPart = offset; - CheckWinReturn(::SetFilePointerEx(handle_.Get(), n_offset, &new_pos, method)); + CheckWinReturn(::SetFilePointerEx(handle_, n_offset, &new_pos, method)); return new_pos.QuadPart; } Index Win32HandleStream::DoRead(std::byte* buffer, Index offset, Index size) { DWORD real_read; - auto r = ::ReadFile(handle_.Get(), static_cast(buffer + offset), size, + auto r = ::ReadFile(handle_, static_cast(buffer + offset), size, &real_read, nullptr); if (r == FALSE) { auto e = ::GetLastError(); @@ -113,15 +114,18 @@ Index Win32HandleStream::DoRead(std::byte* buffer, Index offset, Index size) { Index Win32HandleStream::DoWrite(const std::byte* buffer, Index offset, Index size) { DWORD real_write; - CheckWinReturn(::WriteFile(handle_.Get(), - static_cast(buffer + offset), size, - &real_write, nullptr)); + CheckWinReturn(::WriteFile(handle_, static_cast(buffer + offset), + size, &real_write, nullptr)); return real_write; } void Win32HandleStream::DoClose() { CRU_STREAM_BEGIN_CLOSE + if (auto_close_) { + ::CloseHandle(handle_); + } + handle_ = {}; } -- cgit v1.2.3