all repos — mgba @ 9adfcad1b56e5f42410390e8cb6cfce6f5043134

mGBA Game Boy Advance Emulator

Util: Cleanup of VFileZip and VFile7z
Jeffrey Pfau jeffrey@endrift.com
Thu, 05 Mar 2015 18:40:33 -0800
commit

9adfcad1b56e5f42410390e8cb6cfce6f5043134

parent

a268d462c0ed4d834cf1035bbb645cea2978c86e

4 files changed, 21 insertions(+), 36 deletions(-)

jump to
M src/util/vfs.csrc/util/vfs.c

@@ -378,3 +378,15 @@ return vdede->ent->d_name;

} return 0; } + +ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size) { + size_t bytesRead = 0; + while (bytesRead < size - 1) { + size_t newRead = vf->read(vf, &buffer[bytesRead], 1); + bytesRead += newRead; + if (!newRead || buffer[bytesRead] == '\n') { + break; + } + } + return buffer[bytesRead] = '\0'; +}
M src/util/vfs.hsrc/util/vfs.h

@@ -52,4 +52,6 @@

struct VFile* VDirOptionalOpenFile(struct VDir* dir, const char* realPath, const char* prefix, const char* suffix, int mode); struct VFile* VDirOptionalOpenIncrementFile(struct VDir* dir, const char* realPath, const char* prefix, const char* infix, const char* suffix, int mode); +ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size); + #endif
M src/util/vfs/vfs-lzma.csrc/util/vfs/vfs-lzma.c

@@ -51,7 +51,6 @@

static bool _vf7zClose(struct VFile* vf); static off_t _vf7zSeek(struct VFile* vf, off_t offset, int whence); static ssize_t _vf7zRead(struct VFile* vf, void* buffer, size_t size); -static ssize_t _vf7zReadline(struct VFile* vf, char* buffer, size_t size); static ssize_t _vf7zWrite(struct VFile* vf, const void* buffer, size_t size); static void* _vf7zMap(struct VFile* vf, size_t size, int flags); static void _vf7zUnmap(struct VFile* vf, void* memory, size_t size);

@@ -142,16 +141,12 @@ default:

return -1; } - if (position <= vf7z->offset) { - vf7z->offset = position; - return position; - } - - if (position <= vf7z->size) { - return vf7z->offset; + if (position > vf7z->size) { + return -1; } - return -1; + vf7z->offset = position; + return position; } ssize_t _vf7zRead(struct VFile* vf, void* buffer, size_t size) {

@@ -162,19 +157,8 @@ size = vf7z->size - vf7z->offset;

} memcpy(buffer, vf7z->outBuffer + vf7z->offset + vf7z->bufferOffset, size); + vf7z->offset += size; return size; -} - -ssize_t _vf7zReadline(struct VFile* vf, char* buffer, size_t size) { - size_t bytesRead = 0; - while (bytesRead < size - 1) { - size_t newRead = vf->read(vf, &buffer[bytesRead], 1); - bytesRead += newRead; - if (!newRead || buffer[bytesRead] == '\n') { - break; - } - } - return buffer[bytesRead] = '\0'; } ssize_t _vf7zWrite(struct VFile* vf, const void* buffer, size_t size) {

@@ -301,7 +285,7 @@

vf->d.close = _vf7zClose; vf->d.seek = _vf7zSeek; vf->d.read = _vf7zRead; - vf->d.readline = _vf7zReadline; + vf->d.readline = VFileReadline; vf->d.write = _vf7zWrite; vf->d.map = _vf7zMap; vf->d.unmap = _vf7zUnmap;
M src/util/vfs/vfs-zip.csrc/util/vfs/vfs-zip.c

@@ -38,7 +38,6 @@

static bool _vfzClose(struct VFile* vf); static off_t _vfzSeek(struct VFile* vf, off_t offset, int whence); static ssize_t _vfzRead(struct VFile* vf, void* buffer, size_t size); -static ssize_t _vfzReadline(struct VFile* vf, char* buffer, size_t size); static ssize_t _vfzWrite(struct VFile* vf, const void* buffer, size_t size); static void* _vfzMap(struct VFile* vf, size_t size, int flags); static void _vfzUnmap(struct VFile* vf, void* memory, size_t size);

@@ -188,18 +187,6 @@ }

return bytesRead; } -ssize_t _vfzReadline(struct VFile* vf, char* buffer, size_t size) { - size_t bytesRead = 0; - while (bytesRead < size - 1) { - size_t newRead = vf->read(vf, &buffer[bytesRead], 1); - bytesRead += newRead; - if (!newRead || buffer[bytesRead] == '\n') { - break; - } - } - return buffer[bytesRead] = '\0'; -} - ssize_t _vfzWrite(struct VFile* vf, const void* buffer, size_t size) { // TODO UNUSED(vf);

@@ -296,7 +283,7 @@

vfz->d.close = _vfzClose; vfz->d.seek = _vfzSeek; vfz->d.read = _vfzRead; - vfz->d.readline = _vfzReadline; + vfz->d.readline = VFileReadline; vfz->d.write = _vfzWrite; vfz->d.map = _vfzMap; vfz->d.unmap = _vfzUnmap;