diff options
author | 2024-02-25 02:27:26 +1100 | |
---|---|---|
committer | 2024-02-25 02:27:26 +1100 | |
commit | 1615b8551a3a73532ac234973cfb04dd8ed98ba4 (patch) | |
tree | 25575506b4117afa614b94b4370af7f16eb9dbb5 /src/lib/util/chd.cpp | |
parent | 334ec12e0043ef939be418283235e3dbe5a005fe (diff) |
util/ioprocs.cpp: Added wrappers for common patterns. (#11608)
emu/diimage.h: Removed fread overloads that allocate memory for output.
util/core_file.cpp: Changed output size of load to size_t.
Diffstat (limited to 'src/lib/util/chd.cpp')
-rw-r--r-- | src/lib/util/chd.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/lib/util/chd.cpp b/src/lib/util/chd.cpp index b0e1c1ee510..f5e5ec8e0cc 100644 --- a/src/lib/util/chd.cpp +++ b/src/lib/util/chd.cpp @@ -27,6 +27,7 @@ #include <cstdlib> #include <ctime> #include <new> +#include <tuple> //************************************************************************** @@ -165,13 +166,16 @@ inline void chd_file::file_read(uint64_t offset, void *dest, uint32_t length) co throw std::error_condition(error::NOT_OPEN); // seek and read - m_file->seek(offset, SEEK_SET); + std::error_condition err; + err = m_file->seek(offset, SEEK_SET); + if (err) + throw err; size_t count; - std::error_condition err = m_file->read(dest, length, count); + std::tie(err, count) = read(*m_file, dest, length); if (err) throw err; else if (count != length) - throw std::error_condition(std::errc::io_error); // TODO: revisit this error code (happens if file is cut off) + throw std::error_condition(std::errc::io_error); // TODO: revisit this error code (happens if file is truncated) } @@ -187,13 +191,13 @@ inline void chd_file::file_write(uint64_t offset, const void *source, uint32_t l throw std::error_condition(error::NOT_OPEN); // seek and write - m_file->seek(offset, SEEK_SET); - size_t count; - std::error_condition err = m_file->write(source, length, count); + std::error_condition err; + err = m_file->seek(offset, SEEK_SET); + if (err) + throw err; + std::tie(err, std::ignore) = write(*m_file, source, length); if (err) throw err; - else if (count != length) - throw std::error_condition(std::errc::interrupted); // can theoretically happen if write is inuterrupted by a signal } @@ -232,7 +236,7 @@ inline uint64_t chd_file::file_append(const void *source, uint32_t length, uint3 { uint32_t bytes_to_write = std::min<std::size_t>(sizeof(buffer), delta); size_t count; - err = m_file->write(buffer, bytes_to_write, count); + std::tie(err, count) = write(*m_file, buffer, bytes_to_write); if (err) throw err; delta -= count; @@ -245,12 +249,9 @@ inline uint64_t chd_file::file_append(const void *source, uint32_t length, uint3 err = m_file->tell(offset); if (err) throw err; - size_t count; - err = m_file->write(source, length, count); + std::tie(err, std::ignore) = write(*m_file, source, length); if (err) throw err; - else if (count != length) - throw std::error_condition(std::errc::interrupted); // can theoretically happen if write is interrupted by a signal return offset; } |