diff options
Diffstat (limited to 'src/osd/modules/file/winfile.cpp')
-rw-r--r-- | src/osd/modules/file/winfile.cpp | 88 |
1 files changed, 11 insertions, 77 deletions
diff --git a/src/osd/modules/file/winfile.cpp b/src/osd/modules/file/winfile.cpp index 199537bbdee..173021121f1 100644 --- a/src/osd/modules/file/winfile.cpp +++ b/src/osd/modules/file/winfile.cpp @@ -62,12 +62,12 @@ public: LARGE_INTEGER largeOffset; largeOffset.QuadPart = offset; if (!SetFilePointerEx(m_handle, largeOffset, nullptr, FILE_BEGIN)) - return win_error_to_file_error(GetLastError()); + return win_error_to_error_condition(GetLastError()); // then perform the read DWORD result = 0; if (!ReadFile(m_handle, buffer, length, &result, nullptr)) - return win_error_to_file_error(GetLastError()); + return win_error_to_error_condition(GetLastError()); actual = result; return std::error_condition(); @@ -79,12 +79,12 @@ public: LARGE_INTEGER largeOffset; largeOffset.QuadPart = offset; if (!SetFilePointerEx(m_handle, largeOffset, nullptr, FILE_BEGIN)) - return win_error_to_file_error(GetLastError()); + return win_error_to_error_condition(GetLastError()); // then perform the write DWORD result = 0; if (!WriteFile(m_handle, buffer, length, &result, nullptr)) - return win_error_to_file_error(GetLastError()); + return win_error_to_error_condition(GetLastError()); actual = result; return std::error_condition(); @@ -96,11 +96,11 @@ public: LARGE_INTEGER largeOffset; largeOffset.QuadPart = offset; if (!SetFilePointerEx(m_handle, largeOffset, nullptr, FILE_BEGIN)) - return win_error_to_file_error(GetLastError()); + return win_error_to_error_condition(GetLastError()); // then perform the truncation if (!SetEndOfFile(m_handle)) - return win_error_to_file_error(GetLastError()); + return win_error_to_error_condition(GetLastError()); else return std::error_condition(); } @@ -229,7 +229,7 @@ std::error_condition osd_file::open(std::string const &orig_path, uint32_t openf // if we still failed, clean up and free if (INVALID_HANDLE_VALUE == h) - return win_error_to_file_error(err); + return win_error_to_error_condition(err); } // get the file size @@ -259,7 +259,7 @@ std::error_condition osd_file::open(std::string const &orig_path, uint32_t openf if (NO_ERROR != err) { CloseHandle(h); - return win_error_to_file_error(err); + return win_error_to_error_condition(err); } } @@ -299,7 +299,7 @@ std::error_condition osd_file::remove(std::string const &filename) noexcept std::error_condition filerr; if (!DeleteFile(tempstr.c_str())) - filerr = win_error_to_file_error(GetLastError()); + filerr = win_error_to_error_condition(GetLastError()); return filerr; } @@ -415,12 +415,12 @@ std::error_condition osd_get_full_path(std::string &dst, std::string const &path std::wstring const w_path(osd::text::to_wstring(path)); DWORD const length(GetFullPathNameW(w_path.c_str(), 0, nullptr, nullptr)); if (!length) - return win_error_to_file_error(GetLastError()); + return win_error_to_error_condition(GetLastError()); // allocate a buffer and get the canonical path std::unique_ptr<wchar_t []> buffer(std::make_unique<wchar_t []>(length)); if (!GetFullPathNameW(w_path.c_str(), length, buffer.get(), nullptr)) - return win_error_to_file_error(GetLastError()); + return win_error_to_error_condition(GetLastError()); // convert the result back to UTF-8 osd::text::from_wstring(dst, buffer.get()); @@ -534,69 +534,3 @@ bool osd_is_valid_filepath_char(char32_t uchar) noexcept && !(uchar >= '\x7F' && uchar <= '\x9F') && uchar_isvalid(uchar); } - - - -//============================================================ -// win_error_to_file_error -//============================================================ - -std::error_condition win_error_to_file_error(DWORD error) noexcept -{ - // TODO: work out if there's a better way to do this - switch (error) - { - case ERROR_SUCCESS: - return std::error_condition(); - - case ERROR_INVALID_HANDLE: - return std::errc::bad_file_descriptor; - - case ERROR_OUTOFMEMORY: - return std::errc::not_enough_memory; - - case ERROR_NOT_SUPPORTED: - return std::errc::not_supported; - - case ERROR_FILE_NOT_FOUND: - case ERROR_PATH_NOT_FOUND: - case ERROR_INVALID_NAME: - return std::errc::no_such_file_or_directory; - - case ERROR_FILENAME_EXCED_RANGE: - return std::errc::filename_too_long; - - case ERROR_ACCESS_DENIED: - case ERROR_SHARING_VIOLATION: - return std::errc::permission_denied; - - case ERROR_ALREADY_EXISTS: - return std::errc::file_exists; - - case ERROR_TOO_MANY_OPEN_FILES: - return std::errc::too_many_files_open; - - case ERROR_WRITE_FAULT: - case ERROR_READ_FAULT: - return std::errc::io_error; - - case ERROR_HANDLE_DISK_FULL: - case ERROR_DISK_FULL: - return std::errc::no_space_on_device; - - case ERROR_PATH_BUSY: - case ERROR_BUSY: - return std::errc::device_or_resource_busy; - - case ERROR_FILE_TOO_LARGE: - return std::errc::file_too_large; - - case ERROR_INVALID_ACCESS: - case ERROR_NEGATIVE_SEEK: - case ERROR_BAD_ARGUMENTS: - return std::errc::invalid_argument; - - default: - return std::error_condition(error, std::system_category()); - } -} |