ref: 8b5f8089f293105a48fdd41d976988f1b98a4c19
parent: 76ab0ba30b00f168ed421ecbae616e8e570c163f
parent: 14a2e223997ccdcc3da3e9ecd6e8bfb0d879ab7c
author: Christopher Snowhill <[email protected]>
date: Sat Oct 7 14:26:40 EDT 2017
Merge pull request #70 from SimonN/fix-packfile-getnc-return fix internal getnc to return dumb_ssize_t
--- a/DUMBFILE_SYSTEM.md
+++ b/DUMBFILE_SYSTEM.md
@@ -147,7 +147,7 @@
* the number of bytes successfully read, if it was possible to read at least
one byte.
-* `-1` on error.
+* `-1` on error, when it was not possible to read even a single byte.
This function shall bytes from the file `f` and store them in sequence in the
buffer beginning at `ptr`. It shall read fewer than `n` bytes if end of file
--- a/src/allegro/packfile.c
+++ b/src/allegro/packfile.c
@@ -59,12 +59,15 @@
return c;
}
-static size_t dumb_packfile_getnc(char *ptr, size_t n, void *f) {
+static dumb_ssize_t dumb_packfile_getnc(char *ptr, size_t n, void *f) {
dumb_packfile *file = (dumb_packfile *)f;
- int nr = pack_fread(ptr, n, file->p);
- if (nr > 0)
+ errno = 0;
+ long nr = pack_fread(ptr, n, file->p);
+ if (nr > 0) {
file->pos += nr;
- return nr;
+ return nr;
+ }
+ return errno != 0 ? -1 : 0;
}
static void dumb_packfile_close(void *f) {