VFS: Fix line-reading to return proper values
Jeffrey Pfau jeffrey@endrift.com
Thu, 18 Jun 2015 01:26:46 -0700
2 files changed,
9 insertions(+),
4 deletions(-)
M
CHANGES
→
CHANGES
@@ -45,6 +45,7 @@ - SDL: Fix SDL build when OpenGL is missing
- ARM7: Fix timing of multiplies to use N cycles - GBA: Fix calls to endian-independent loadstores - GBA Video: Fix windows not affecting sprites + - VFS: Fix line-reading to return proper values Misc: - Qt: Handle saving input settings better - Debugger: Free watchpoints in addition to breakpoints
M
src/util/vfs.c
→
src/util/vfs.c
@@ -6,15 +6,19 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "vfs.h" ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size) { - size_t bytesRead = 0; + ssize_t bytesRead = 0; while (bytesRead < size - 1) { - size_t newRead = vf->read(vf, &buffer[bytesRead], 1); + ssize_t newRead = vf->read(vf, &buffer[bytesRead], 1); + if (newRead <= 0) { + break; + } bytesRead += newRead; - if (!newRead || buffer[bytesRead] == '\n') { + if (buffer[bytesRead] == '\n') { break; } } - return buffer[bytesRead] = '\0'; + buffer[bytesRead] = '\0'; + return bytesRead; } ssize_t VFileWrite32LE(struct VFile* vf, int32_t word) {