History

fix internal getnc to return dumb_ssize_t

Return type should match what we declare in dumb.h. Temporary variable should be long, because A4 returns a long here. Setting/checking errno to return -1 when we can't read anything, but returning number of bytes read if we read at least a few bytes. Consider clarifying the getnc spec what we should return when the caller wishes for 20 bytes, we can only read 10, then encounter an error. We should probably return 10 then.

Simon Naarmann committed 9 years ago

Commit 14a2e221 parent e9320b62 files · +8 −5Browse files

Unified · Split

2 files
  1. DUMBFILE_SYSTEM.md +1 −1
  2. src/allegro/packfile.c +7 −4
DUMBFILE_SYSTEM.md+1−1
@@ -147,7 +147,7 @@ Returns as `dumb_ssize_t`: · 146 unmodified lines
147147 * the number of bytes successfully read, if it was possible to read at least
148148 one byte.
149149
150−* `-1` on error.
150+* `-1` on error, when it was not possible to read even a single byte.
151151
152152 This function shall bytes from the file `f` and store them in sequence in the
153153 buffer beginning at `ptr`. It shall read fewer than `n` bytes if end of file
src/allegro/packfile.c+7−4
@@ -59,12 +59,15 @@ static int dumb_packfile_getc(void *f) { · 58 unmodified lines
5959 return c;
6060 }
6161
62−static size_t dumb_packfile_getnc(char *ptr, size_t n, void *f) {
62+static dumb_ssize_t dumb_packfile_getnc(char *ptr, size_t n, void *f) {
6363 dumb_packfile *file = (dumb_packfile *)f;
64− int nr = pack_fread(ptr, n, file->p);
65− if (nr > 0)
64+ errno = 0;
65+ long nr = pack_fread(ptr, n, file->p);
66+ if (nr > 0) {
6667 file->pos += nr;
67− return nr;
68+ return nr;
69+ }
70+ return errno != 0 ? -1 : 0;
6871 }
6972
7073 static void dumb_packfile_close(void *f) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t