diff options
author | bunnei <bunneidev@gmail.com> | 2014-09-18 22:27:06 -0400 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2014-09-18 22:27:06 -0400 |
commit | a9630a9d2b432bea7bdfef4aa462035b98b34517 (patch) | |
tree | 258010943e989fc61a2a439ff15ead7ed3d11a6f /src/common/file_util.h | |
parent | 1c79a4f10c1eb679b1ab253572a45a7c7df99691 (diff) | |
parent | 3a570a9fee57d77923eb1e71dbadcd08bb39aa25 (diff) |
Merge pull request #70 from linkmauve/master
Implement filesystem services, and the required kernel objects.
Diffstat (limited to 'src/common/file_util.h')
-rw-r--r-- | src/common/file_util.h | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h index fdae5c9c8..897cbd77e 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -43,7 +43,7 @@ enum { NUM_PATH_INDICES }; -namespace File +namespace FileUtil { // FileSystem tree node/ @@ -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); } |