diff --git a/Utilities/File.cpp b/Utilities/File.cpp index b616ff9ff2..66b1c2f065 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -682,11 +682,10 @@ bool fs::truncate_file(const std::string& path, u64 length) return false; } - LARGE_INTEGER distance; - distance.QuadPart = length; + FILE_END_OF_FILE_INFO _eof; + _eof.EndOfFile.QuadPart = length; - // Seek and truncate - if (!SetFilePointerEx(handle, distance, NULL, FILE_BEGIN) || !SetEndOfFile(handle)) + if (!SetFileInformationByHandle(handle, FileEndOfFileInfo, &_eof, sizeof(_eof))) { g_tls_error = to_error(GetLastError()); CloseHandle(handle); @@ -846,23 +845,15 @@ fs::file::file(const std::string& path, bs_t mode) bool trunc(u64 length) override { - LARGE_INTEGER old, pos; + FILE_END_OF_FILE_INFO _eof; + _eof.EndOfFile.QuadPart = length; - pos.QuadPart = 0; - if (!SetFilePointerEx(m_handle, pos, &old, FILE_CURRENT)) // get old position + if (!SetFileInformationByHandle(m_handle, FileEndOfFileInfo, &_eof, sizeof(_eof))) { g_tls_error = to_error(GetLastError()); return false; } - pos.QuadPart = length; - if (!SetFilePointerEx(m_handle, pos, NULL, FILE_BEGIN)) // set new position - { - g_tls_error = to_error(GetLastError()); - return false; - } - - verify("file::trunc" HERE), SetEndOfFile(m_handle), SetFilePointerEx(m_handle, old, NULL, FILE_BEGIN); return true; } diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index 7843048e7c..367903bfcd 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -348,12 +348,10 @@ logs::file_writer::~file_writer() #ifdef _WIN32 UnmapViewOfFile(m_fptr); CloseHandle(m_fmap); - m_file.seek(m_size); - SetEndOfFile(m_file.get_handle()); #else ::munmap(m_fptr, s_log_size); - m_file.trunc(m_size); #endif + m_file.trunc(m_size); } void logs::file_writer::log(logs::level sev, const char* text, std::size_t size)