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
147* the number of bytes successfully read, if it was possible to read at least147* the number of bytes successfully read, if it was possible to read at least
148one byte.148one byte.
149 149
150* `-1` on error.150* `-1` on error, when it was not possible to read even a single byte.
151 151
152This function shall bytes from the file `f` and store them in sequence in the152This function shall bytes from the file `f` and store them in sequence in the
153buffer beginning at `ptr`. It shall read fewer than `n` bytes if end of file153buffer 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
59 return c;59 return c;
60}60}
61 61
62static size_t dumb_packfile_getnc(char *ptr, size_t n, void *f) {62static dumb_ssize_t dumb_packfile_getnc(char *ptr, size_t n, void *f) {
63 dumb_packfile *file = (dumb_packfile *)f;63 dumb_packfile *file = (dumb_packfile *)f;
64 int nr = pack_fread(ptr, n, file->p);64 errno = 0;
65 if (nr > 0)65 long nr = pack_fread(ptr, n, file->p);
66 if (nr > 0) {
66 file->pos += nr;67 file->pos += nr;
67 return nr;68 return nr;
69 }
70 return errno != 0 ? -1 : 0;
68}71}
69 72
70static void dumb_packfile_close(void *f) {73static 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