summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/fileio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/fileio.cpp')
-rw-r--r--src/emu/fileio.cpp41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/emu/fileio.cpp b/src/emu/fileio.cpp
index 6d5d6b8a806..c0341b93368 100644
--- a/src/emu/fileio.cpp
+++ b/src/emu/fileio.cpp
@@ -14,6 +14,8 @@
#include "util/path.h"
#include "util/unzip.h"
+#include <tuple>
+
//#define VERBOSE 1
#define LOG_OUTPUT_FUNC osd_printf_verbose
#include "logmacro.h"
@@ -107,7 +109,7 @@ path_iterator &path_iterator::operator=(path_iterator const &that)
// multipath sequence
//-------------------------------------------------
-bool path_iterator::next(std::string &buffer, const char *name)
+bool path_iterator::next(std::string &buffer)
{
// if none left, return false to indicate we are done
if (!m_is_first && (m_searchpath.cend() == m_current))
@@ -120,10 +122,6 @@ bool path_iterator::next(std::string &buffer, const char *name)
if (m_searchpath.cend() != m_current)
++m_current;
- // append the name if we have one
- if (name)
- util::path_append(buffer, name);
-
// bump the index and return true
m_is_first = false;
return true;
@@ -160,9 +158,13 @@ const osd::directory::entry *file_enumerator::next(const char *subdir)
while (!m_curdir)
{
// if we fail to get anything more, we're done
- if (!m_iterator.next(m_pathbuffer, subdir))
+ if (!m_iterator.next(m_pathbuffer))
return nullptr;
+ // append the subdir if we have one
+ if (subdir)
+ util::path_append(m_pathbuffer, subdir);
+
// open the path
m_curdir = osd::directory::open(m_pathbuffer);
}
@@ -259,7 +261,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 +281,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;
}
@@ -532,9 +533,10 @@ u32 emu_file::read(void *buffer, u32 length)
return 0;
// read the data if we can
+ std::error_condition err;
size_t actual = 0;
if (m_file)
- m_file->read(buffer, length, actual);
+ std::tie(err, actual) = util::read(*m_file, buffer, length);
return actual;
}
@@ -602,9 +604,10 @@ u32 emu_file::write(const void *buffer, u32 length)
{
// FIXME: need better interface to report errors
// write the data if we can
+ std::error_condition err;
size_t actual = 0;
if (m_file)
- m_file->write(buffer, length, actual);
+ std::tie(err, actual) = util::write(*m_file, buffer, length);
return actual;
}
@@ -628,7 +631,7 @@ int emu_file::puts(std::string_view s)
// vfprintf - vfprintf to a text file
//-------------------------------------------------
-int emu_file::vprintf(util::format_argument_pack<std::ostream> const &args)
+int emu_file::vprintf(util::format_argument_pack<char> const &args)
{
// write the data if we can
return m_file ? m_file->vprintf(args) : 0;
@@ -805,7 +808,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 +816,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();