From 8eb4f3ca4d1210e654248605a5fa48546b1d4ee5 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 1 Nov 2015 16:49:53 -0800 Subject: [PATCH] VFS: Fix VFileReadline and remove _vfdReadline --- CHANGES | 1 + src/util/vfs.c | 2 +- src/util/vfs/vfs-fd.c | 17 +---------------- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/CHANGES b/CHANGES index 52d068c58..2e32d1a6d 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,7 @@ Bugfixes: - Qt: Fix a race condition in PainterGL that could lead to a crash - Qt: Fix clear button/analog buttons in gamepad mapper on some platforms - GBA Video: Fix _mix for 15-bit color + - VFS: Fix VFileReadline and remove _vfdReadline Misc: - Qt: Window size command line options are now supported - Qt: Increase usability of key mapper diff --git a/src/util/vfs.c b/src/util/vfs.c index b50603b25..3f6adb9cb 100644 --- a/src/util/vfs.c +++ b/src/util/vfs.c @@ -119,7 +119,7 @@ ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size) { break; } bytesRead += newRead; - if (buffer[bytesRead] == '\n') { + if (buffer[bytesRead - newRead] == '\n') { break; } } diff --git a/src/util/vfs/vfs-fd.c b/src/util/vfs/vfs-fd.c index ce57c38f9..59aa0706d 100644 --- a/src/util/vfs/vfs-fd.c +++ b/src/util/vfs/vfs-fd.c @@ -24,7 +24,6 @@ struct VFileFD { static bool _vfdClose(struct VFile* vf); static off_t _vfdSeek(struct VFile* vf, off_t offset, int whence); static ssize_t _vfdRead(struct VFile* vf, void* buffer, size_t size); -static ssize_t _vfdReadline(struct VFile* vf, char* buffer, size_t size); static ssize_t _vfdWrite(struct VFile* vf, const void* buffer, size_t size); static void* _vfdMap(struct VFile* vf, size_t size, int flags); static void _vfdUnmap(struct VFile* vf, void* memory, size_t size); @@ -61,7 +60,7 @@ struct VFile* VFileFromFD(int fd) { vfd->d.close = _vfdClose; vfd->d.seek = _vfdSeek; vfd->d.read = _vfdRead; - vfd->d.readline = _vfdReadline; + vfd->d.readline = VFileReadline; vfd->d.write = _vfdWrite; vfd->d.map = _vfdMap; vfd->d.unmap = _vfdUnmap; @@ -91,20 +90,6 @@ ssize_t _vfdRead(struct VFile* vf, void* buffer, size_t size) { return read(vfd->fd, buffer, size); } -ssize_t _vfdReadline(struct VFile* vf, char* buffer, size_t size) { - struct VFileFD* vfd = (struct VFileFD*) vf; - size_t bytesRead = 0; - while (bytesRead < size - 1) { - size_t newRead = read(vfd->fd, &buffer[bytesRead], 1); - if (!newRead || buffer[bytesRead] == '\n') { - break; - } - bytesRead += newRead; - } - buffer[bytesRead] = '\0'; - return bytesRead; -} - ssize_t _vfdWrite(struct VFile* vf, const void* buffer, size_t size) { struct VFileFD* vfd = (struct VFileFD*) vf; return write(vfd->fd, buffer, size);