diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2014-09-12 00:16:54 +0200 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2014-09-17 16:35:45 +0200 |
commit | edaf59a759f26f2caf6ba70de47f52b667743e5c (patch) | |
tree | 178756c410da5be593d8c1899a5be93026f1a0fc | |
parent | Merge pull request #107 from lioncash/sprintf (diff) | |
download | yuzu-edaf59a759f26f2caf6ba70de47f52b667743e5c.tar yuzu-edaf59a759f26f2caf6ba70de47f52b667743e5c.tar.gz yuzu-edaf59a759f26f2caf6ba70de47f52b667743e5c.tar.bz2 yuzu-edaf59a759f26f2caf6ba70de47f52b667743e5c.tar.lz yuzu-edaf59a759f26f2caf6ba70de47f52b667743e5c.tar.xz yuzu-edaf59a759f26f2caf6ba70de47f52b667743e5c.tar.zst yuzu-edaf59a759f26f2caf6ba70de47f52b667743e5c.zip |
-rw-r--r-- | src/common/file_util.h | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h index fdae5c9c8..8efff4958 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -151,29 +151,41 @@ public: bool Close(); template <typename T> - bool ReadArray(T* data, size_t length) + size_t ReadArray(T* data, size_t length) { - if (!IsOpen() || length != std::fread(data, sizeof(T), length, m_file)) + if (!IsOpen()) { m_good = false; + return -1; + } - return m_good; + size_t items_read = std::fread(data, sizeof(T), length, m_file); + if (items_read != length) + m_good = false; + + return items_read; } template <typename T> - bool WriteArray(const T* data, size_t length) + size_t WriteArray(const T* data, size_t length) { - if (!IsOpen() || length != std::fwrite(data, sizeof(T), length, m_file)) + if (!IsOpen()) { + m_good = false; + return -1; + } + + size_t items_written = std::fwrite(data, sizeof(T), length, m_file); + if (items_written != length) m_good = false; - return m_good; + return items_written; } - bool ReadBytes(void* data, size_t length) + size_t ReadBytes(void* data, size_t length) { return ReadArray(reinterpret_cast<char*>(data), length); } - bool WriteBytes(const void* data, size_t length) + size_t WriteBytes(const void* data, size_t length) { return WriteArray(reinterpret_cast<const char*>(data), length); } |