diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-03-29 22:41:26 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-03-29 22:41:26 +0300 |
commit | 8f95378c3be89c06c722da03ddbd3641c4fc2323 (patch) | |
tree | 4f1c14fb0ba57793f8979df43ffd293533606e1b /src/fs/virtfs/virtfsrwops.cpp | |
parent | fc31f1003bec7e0117421a8c58668e61849eeba5 (diff) | |
download | plus-8f95378c3be89c06c722da03ddbd3641c4fc2323.tar.gz plus-8f95378c3be89c06c722da03ddbd3641c4fc2323.tar.bz2 plus-8f95378c3be89c06c722da03ddbd3641c4fc2323.tar.xz plus-8f95378c3be89c06c722da03ddbd3641c4fc2323.zip |
Move rwops code into virtfs namespace.
Diffstat (limited to 'src/fs/virtfs/virtfsrwops.cpp')
-rw-r--r-- | src/fs/virtfs/virtfsrwops.cpp | 100 |
1 files changed, 46 insertions, 54 deletions
diff --git a/src/fs/virtfs/virtfsrwops.cpp b/src/fs/virtfs/virtfsrwops.cpp index f44cc6601..e66748967 100644 --- a/src/fs/virtfs/virtfsrwops.cpp +++ b/src/fs/virtfs/virtfsrwops.cpp @@ -52,17 +52,9 @@ #include "debug.h" -#ifdef USE_SDL2 -#define RWOPSINT int64_t -#define RWOPSSIZE size_t -#else // USE_SDL2 -#define RWOPSINT int32_t -#define RWOPSSIZE int -#endif // USE_SDL2 - -static RWOPSINT virtfsrwops_seek(SDL_RWops *const rw, - const RWOPSINT offset, - const int whence) +RWOPSINT VirtFs::rwops_seek(SDL_RWops *const rw, + const RWOPSINT offset, + const int whence) { if (!rw) return -1; @@ -80,14 +72,14 @@ static RWOPSINT virtfsrwops_seek(SDL_RWops *const rw, if (current == -1) { logger->assertLog( - "virtfsrwops_seek: Can't find position in file."); + "VirtFs::rwops_seek: Can't find position in file."); return -1; } /* if */ pos = CAST_S32(current); if (static_cast<int64_t>(pos) != current) { - logger->assertLog("virtfsrwops_seek: " + logger->assertLog("VirtFs::rwops_seek: " "Can't fit current file position in an int!"); return -1; } /* if */ @@ -102,14 +94,14 @@ static RWOPSINT virtfsrwops_seek(SDL_RWops *const rw, const int64_t len = VirtFs::fileLength(handle); if (len == -1) { - logger->assertLog("virtfsrwops_seek:Can't find end of file."); + logger->assertLog("VirtFs::rwops_seek:Can't find end of file."); return -1; } /* if */ pos = static_cast<RWOPSINT>(len); if (static_cast<int64_t>(pos) != len) { - logger->assertLog("virtfsrwops_seek: " + logger->assertLog("VirtFs::rwops_seek: " "Can't fit end-of-file position in an int!"); return -1; } /* if */ @@ -118,30 +110,30 @@ static RWOPSINT virtfsrwops_seek(SDL_RWops *const rw, } /* else if */ else { - logger->assertLog("virtfsrwops_seek: Invalid 'whence' parameter."); + logger->assertLog("VirtFs::rwops_seek: Invalid 'whence' parameter."); return -1; } /* else */ if (pos < 0) { - logger->assertLog("virtfsrwops_seek: " + logger->assertLog("VirtFs::rwops_seek: " "Attempt to seek past start of file."); return -1; } /* if */ if (!VirtFs::seek(handle, static_cast<uint64_t>(pos))) { - logger->assertLog("virtfsrwops_seek: seek error."); + logger->assertLog("VirtFs::rwops_seek: seek error."); return -1; } /* if */ return pos; -} /* virtfsrwops_seek */ +} /* VirtFs::rwops_seek */ -static RWOPSSIZE virtfsrwops_read(SDL_RWops *const rw, - void *const ptr, - const RWOPSSIZE size, - const RWOPSSIZE maxnum) +RWOPSSIZE VirtFs::rwops_read(SDL_RWops *const rw, + void *const ptr, + const RWOPSSIZE size, + const RWOPSSIZE maxnum) { if (!rw) return 0; @@ -154,17 +146,17 @@ static RWOPSSIZE virtfsrwops_read(SDL_RWops *const rw, { if (!VirtFs::eof(handle)) /* not EOF? Must be an error. */ { - logger->assertLog("virtfsrwops_seek: read error."); + logger->assertLog("VirtFs::rwops_seek: read error."); } } /* if */ return CAST_S32(rc); -} /* virtfsrwops_read */ +} /* VirtFs::rwops_read */ -static RWOPSSIZE virtfsrwops_write(SDL_RWops *const rw, - const void *const ptr, - const RWOPSSIZE size, - const RWOPSSIZE num) +RWOPSSIZE VirtFs::rwops_write(SDL_RWops *const rw, + const void *const ptr, + const RWOPSSIZE size, + const RWOPSSIZE num) { if (!rw) return 0; @@ -175,13 +167,13 @@ static RWOPSSIZE virtfsrwops_write(SDL_RWops *const rw, CAST_U32(num)); if (rc != static_cast<int64_t>(num)) { - logger->assertLog("virtfsrwops_seek: write error."); + logger->assertLog("VirtFs::rwops_seek: write error."); } return CAST_S32(rc); -} /* virtfsrwops_write */ +} /* VirtFs::rwops_write */ -static int virtfsrwops_close(SDL_RWops *const rw) +int VirtFs::rwops_close(SDL_RWops *const rw) { if (!rw) return 0; @@ -189,30 +181,30 @@ static int virtfsrwops_close(SDL_RWops *const rw) rw->hidden.unknown.data1); if (!VirtFs::close(handle)) { - logger->assertLog("virtfsrwops_seek: close error."); + logger->assertLog("VirtFs::rwops_seek: close error."); return -1; } /* if */ SDL_FreeRW(rw); return 0; -} /* virtfsrwops_close */ +} /* VirtFs::rwops_close */ #ifdef USE_SDL2 -static RWOPSINT virtfsrwops_size(SDL_RWops *const rw) +RWOPSINT VirtFs::rwops_size(SDL_RWops *const rw) { VirtFile *const handle = static_cast<VirtFile *const>( rw->hidden.unknown.data1); return VirtFs::fileLength(handle); -} /* virtfsrwops_size */ +} /* VirtFs::rwops_size */ #endif // USE_SDL2 -static SDL_RWops *create_rwops(VirtFile *const file) +SDL_RWops *VirtFs::create_rwops(VirtFile *const file) { SDL_RWops *retval = nullptr; if (!file) { - logger->assertLog("virtfsrwops_seek: create rwops error."); + logger->assertLog("VirtFs::rwops_seek: create rwops error."); } else { @@ -220,31 +212,31 @@ static SDL_RWops *create_rwops(VirtFile *const file) if (retval) { #ifdef USE_SDL2 - retval->size = &virtfsrwops_size; + retval->size = &VirtFs::rwops_size; #endif // USE_SDL2 - retval->seek = &virtfsrwops_seek; - retval->read = &virtfsrwops_read; - retval->write = &virtfsrwops_write; - retval->close = &virtfsrwops_close; + retval->seek = &VirtFs::rwops_seek; + retval->read = &VirtFs::rwops_read; + retval->write = &VirtFs::rwops_write; + retval->close = &VirtFs::rwops_close; retval->hidden.unknown.data1 = file; } /* if */ } /* else */ return retval; -} /* create_rwops */ +} /* VirtFs::create_rwops */ -SDL_RWops *VirtFs::MakeRWops(VirtFile *const handle) +SDL_RWops *VirtFs::makeRwops(VirtFile *const handle) { SDL_RWops *retval = nullptr; if (!handle) { - logger->assertLog("virtfsrwops_seek: NULL pointer passed to " + logger->assertLog("VirtFs::rwops_seek: NULL pointer passed to " "RWopsmakeRWops()."); } else { - retval = create_rwops(handle); + retval = VirtFs::create_rwops(handle); } return retval; @@ -261,7 +253,7 @@ static bool checkFilePath(const std::string &restrict fname) } #endif // __APPLE__ -SDL_RWops *VirtFs::RWopsOpenRead(const std::string &restrict fname) +SDL_RWops *VirtFs::rwopsOpenRead(const std::string &restrict fname) { BLOCK_START("RWopsopenRead") #ifdef __APPLE__ @@ -274,34 +266,34 @@ SDL_RWops *VirtFs::RWopsOpenRead(const std::string &restrict fname) #endif // USE_FUZZER #ifdef USE_PROFILER - SDL_RWops *const ret = create_rwops(VirtFs::openRead(fname)); + SDL_RWops *const ret = VirtFs::create_rwops(VirtFs::openRead(fname)); BLOCK_END("RWopsopenRead") return ret; #else // USE_PROFILER - return create_rwops(VirtFs::openRead(fname)); + return VirtFs::create_rwops(VirtFs::openRead(fname)); #endif // USE_PROFILER } /* RWopsopenRead */ -SDL_RWops *VirtFs::RWopsOpenWrite(const std::string &restrict fname) +SDL_RWops *VirtFs::rwopsOpenWrite(const std::string &restrict fname) { #ifdef __APPLE__ if (!checkFilePath(fname)) return nullptr; #endif // __APPLE__ - return create_rwops(VirtFs::openWrite(fname)); + return VirtFs::create_rwops(VirtFs::openWrite(fname)); } /* RWopsopenWrite */ -SDL_RWops *VirtFs::RWopsOpenAppend(const std::string &restrict fname) +SDL_RWops *VirtFs::rwopsOpenAppend(const std::string &restrict fname) { #ifdef __APPLE__ if (!checkFilePath(fname)) return nullptr; #endif // __APPLE__ - return create_rwops(VirtFs::openAppend(fname)); + return VirtFs::create_rwops(VirtFs::openAppend(fname)); } /* RWopsopenAppend */ /* end of virtfsrwops.c ... */ |