summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/fileio.cpp
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2022-04-19 14:22:04 -0400
committer AJR <ajrhacker@users.noreply.github.com>2022-04-19 14:28:45 -0400
commitb45569d964aa8fae416d2049ba70699f5b2d7837 (patch)
tree522b58375072a7b7f3acc36081de7daa9302417d /src/emu/fileio.cpp
parent7780f53ffd266ad7a88058ecda056e5eeea3bc9f (diff)
File handling cleanup
- Remove fgetc, fgets and ptr methods from device_image_interface. - Remove the core_file::buffer method to read an entire file into memory and rewrite emu_file::hashes to not depend on it. - Make core_in_memory_file a final class; now that buffering is gone, core_osd_file no longer subclasses it but a new superclass that retains some common methods. - Rename the offset and length methods used internally in core_file implementations to index and size due to frequent clashes with parameter names. - Convert comments in util/corefile.cpp to C++ style. - Add a new overload of the hash_collection::compute method which hashes data from a random_read stream, reading it into memory one chunk at a time. As a result, the hash_collection::begin and hash_collection::end methods have been removed as obsolete (similar methods are now used internally only). - Enhance error messages for the frontend media identifier when it encounters file errors.
Diffstat (limited to 'src/emu/fileio.cpp')
-rw-r--r--src/emu/fileio.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/emu/fileio.cpp b/src/emu/fileio.cpp
index 21634d8f211..a1bf4adbcb4 100644
--- a/src/emu/fileio.cpp
+++ b/src/emu/fileio.cpp
@@ -259,7 +259,7 @@ util::hash_collection &emu_file::hashes(std::string_view types)
// determine which hashes we need
std::string needed;
for (char scan : types)
- if (already_have.find_first_of(scan) == -1)
+ if (already_have.find_first_of(scan) == std::string::npos)
needed.push_back(scan);
// if we need nothing, skip it
@@ -279,15 +279,14 @@ util::hash_collection &emu_file::hashes(std::string_view types)
return m_hashes;
}
- // read the data if we can
- const u8 *filedata = (const u8 *)m_file->buffer();
- if (filedata == nullptr)
+ std::uint64_t length;
+ if (m_file->length(length))
return m_hashes;
- // compute the hash
- std::uint64_t length;
- if (!m_file->length(length))
- m_hashes.compute(filedata, length, needed.c_str());
+ // hash the data
+ std::size_t actual;
+ (void)m_hashes.compute(*m_file, 0U, length, actual, needed.c_str()); // FIXME: need better interface to report errors
+
return m_hashes;
}
@@ -805,7 +804,7 @@ std::error_condition emu_file::load_zipped_file()
m_zipdata.resize(m_ziplength);
// read the data into our buffer and return
- auto const ziperr = m_zipfile->decompress(&m_zipdata[0], m_zipdata.size());
+ auto const ziperr = m_zipfile->decompress(m_zipdata.data(), m_zipdata.size());
if (ziperr)
{
m_zipdata.clear();
@@ -813,7 +812,7 @@ std::error_condition emu_file::load_zipped_file()
}
// convert to RAM file
- std::error_condition const filerr = util::core_file::open_ram(&m_zipdata[0], m_zipdata.size(), m_openflags, m_file);
+ std::error_condition const filerr = util::core_file::open_ram(m_zipdata.data(), m_zipdata.size(), m_openflags, m_file);
if (filerr)
{
m_zipdata.clear();