diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-02-10 21:18:26 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-02-10 21:18:26 +0300 |
commit | c6277401fb4dafbe08bac534e0de7796f70a0d19 (patch) | |
tree | 7c32dd8ee76bdbf0d6f68de3aaf08b64b1d57080 | |
parent | 6c9c56b70db43f4100863d312835fce763698008 (diff) | |
download | manaverse-c6277401fb4dafbe08bac534e0de7796f70a0d19.tar.gz manaverse-c6277401fb4dafbe08bac534e0de7796f70a0d19.tar.bz2 manaverse-c6277401fb4dafbe08bac534e0de7796f70a0d19.tar.xz manaverse-c6277401fb4dafbe08bac534e0de7796f70a0d19.zip |
Add some missing functions into virtfs.
-rw-r--r-- | src/utils/physfsrwops.cpp | 34 | ||||
-rw-r--r-- | src/utils/virtfs.cpp | 28 | ||||
-rw-r--r-- | src/utils/virtfs.h | 10 |
3 files changed, 52 insertions, 20 deletions
diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp index 9af838070..e642f71aa 100644 --- a/src/utils/physfsrwops.cpp +++ b/src/utils/physfsrwops.cpp @@ -58,17 +58,17 @@ static PHYSFSINT physfsrwops_seek(SDL_RWops *const rw, const PHYSFSINT offset, } /* if */ else if (whence == SEEK_CUR) { - const PHYSFS_sint64 current = PHYSFS_tell(handle); + const int64_t current = VirtFs::tell(handle); if (current == -1) { logger->assertLog( "physfsrwops_seek: Can't find position in file: %s", - PHYSFS_getLastError()); + VirtFs::getLastError()); return -1; } /* if */ pos = CAST_S32(current); - if (static_cast<PHYSFS_sint64>(pos) != current) + if (static_cast<int64_t>(pos) != current) { logger->assertLog("physfsrwops_seek: " "Can't fit current file position in an int!"); @@ -82,16 +82,16 @@ static PHYSFSINT physfsrwops_seek(SDL_RWops *const rw, const PHYSFSINT offset, } /* else if */ else if (whence == SEEK_END) { - const PHYSFS_sint64 len = PHYSFS_fileLength(handle); + const int64_t len = VirtFs::fileLength(handle); if (len == -1) { logger->assertLog("physfsrwops_seek:Can't find end of file: %s", - PHYSFS_getLastError()); + VirtFs::getLastError()); return -1; } /* if */ pos = static_cast<PHYSFSINT>(len); - if (static_cast<PHYSFS_sint64>(pos) != len) + if (static_cast<int64_t>(pos) != len) { logger->assertLog("physfsrwops_seek: " "Can't fit end-of-file position in an int!"); @@ -113,10 +113,10 @@ static PHYSFSINT physfsrwops_seek(SDL_RWops *const rw, const PHYSFSINT offset, return -1; } /* if */ - if (!PHYSFS_seek(handle, static_cast<PHYSFS_uint64>(pos))) + if (!VirtFs::seek(handle, static_cast<uint64_t>(pos))) { logger->assertLog("physfsrwops_seek: seek error: %s", - PHYSFS_getLastError()); + VirtFs::getLastError()); return -1; } /* if */ @@ -132,12 +132,12 @@ static PHYSFSSIZE physfsrwops_read(SDL_RWops *const rw, return 0; PHYSFS_file *const handle = static_cast<PHYSFS_file *const>( rw->hidden.unknown.data1); - const PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, + const int64_t rc = VirtFs::read(handle, ptr, CAST_U32(size), CAST_U32(maxnum)); - if (rc != static_cast<PHYSFS_sint64>(maxnum)) + if (rc != static_cast<int64_t>(maxnum)) { - if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */ + if (!VirtFs::eof(handle)) /* not EOF? Must be an error. */ { logger->assertLog("physfsrwops_seek: read error: %s", PHYSFS_getLastError()); @@ -155,10 +155,10 @@ static PHYSFSSIZE physfsrwops_write(SDL_RWops *const rw, const void *ptr, return 0; PHYSFS_file *const handle = static_cast<PHYSFS_file *const>( rw->hidden.unknown.data1); - const PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, + const int64_t rc = VirtFs::write(handle, ptr, CAST_U32(size), CAST_U32(num)); - if (rc != static_cast<PHYSFS_sint64>(num)) + if (rc != static_cast<int64_t>(num)) { logger->assertLog("physfsrwops_seek: write error: %s", PHYSFS_getLastError()); @@ -173,10 +173,10 @@ static int physfsrwops_close(SDL_RWops *const rw) return 0; PHYSFS_file *const handle = static_cast<PHYSFS_file*>( rw->hidden.unknown.data1); - if (!PHYSFS_close(handle)) + if (!VirtFs::close(handle)) { logger->assertLog("physfsrwops_seek: close error: %s", - PHYSFS_getLastError()); + VirtFs::getLastError()); return -1; } /* if */ @@ -198,7 +198,7 @@ static PHYSFSINT physfsrwops_size(SDL_RWops *const rw) { PHYSFS_file *const handle = static_cast<PHYSFS_file*>( rw->hidden.unknown.data1); - return PHYSFS_fileLength(handle); + return VirtFs::fileLength(handle); } /* physfsrwops_size */ #endif // USE_SDL2 @@ -209,7 +209,7 @@ static SDL_RWops *create_rwops(PHYSFS_file *const handle) if (!handle) { logger->assertLog("physfsrwops_seek: create rwops error: %s", - PHYSFS_getLastError()); + VirtFs::getLastError()); } else { diff --git a/src/utils/virtfs.cpp b/src/utils/virtfs.cpp index 3211d91dd..af000376a 100644 --- a/src/utils/virtfs.cpp +++ b/src/utils/virtfs.cpp @@ -185,9 +185,9 @@ namespace VirtFs return PHYSFS_getLastError(); } - void close(PHYSFS_file *const file) + int close(PHYSFS_file *const file) { - PHYSFS_close(file); + return PHYSFS_close(file); } int64_t read(PHYSFS_File *const file, @@ -198,8 +198,32 @@ namespace VirtFs return PHYSFS_read(file, buffer, objSize, objCount); } + int64_t write(PHYSFS_File *const file, + const void *const buffer, + const uint32_t objSize, + const uint32_t objCount) + { + return PHYSFS_write(file, buffer, objSize, objCount); + } + int64_t fileLength(PHYSFS_File *const file) { return PHYSFS_fileLength(file); } + + int64_t tell(PHYSFS_File *const file) + { + return PHYSFS_tell(file); + } + + int seek(PHYSFS_File *const file, + const uint64_t pos) + { + return PHYSFS_seek(file, pos); + } + + int eof(PHYSFS_File *const file) + { + return PHYSFS_eof(file); + } } // namespace PhysFs diff --git a/src/utils/virtfs.h b/src/utils/virtfs.h index 8cbfe8c51..66149c903 100644 --- a/src/utils/virtfs.h +++ b/src/utils/virtfs.h @@ -57,8 +57,16 @@ namespace VirtFs void *const buffer, const uint32_t objSize, const uint32_t objCount); - void close(PHYSFS_file *const file); + int64_t write(PHYSFS_File *const file, + const void *const buffer, + const uint32_t objSize, + const uint32_t objCount); + int close(PHYSFS_file *const file); int64_t fileLength(PHYSFS_File *const file); + int64_t tell(PHYSFS_File *const file); + int seek(PHYSFS_File *const file, + const uint64_t pos); + int eof(PHYSFS_File *const file); } // namespace PhysFs extern const char *dirSeparator; |