diff options
author | Tor Andersson <tor@ghostscript.com> | 2011-03-06 13:30:01 +0000 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2011-03-06 13:30:01 +0000 |
commit | 2d919ffba311dde73dc957f325ee55c7ce4f66fa (patch) | |
tree | 4bc02aa664c92a1002cec047a7ccece22eee77e2 /fitz/stm_read.c | |
parent | 9dee36047ab01f929582fa7b715af392f2de7d24 (diff) | |
download | mupdf-2d919ffba311dde73dc957f325ee55c7ce4f66fa.tar.xz |
Add explicit EOF testing functions.
Diffstat (limited to 'fitz/stm_read.c')
-rw-r--r-- | fitz/stm_read.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/fitz/stm_read.c b/fitz/stm_read.c index af5afab6..e5ead914 100644 --- a/fitz/stm_read.c +++ b/fitz/stm_read.c @@ -12,7 +12,7 @@ fz_read(fz_stream *stm, unsigned char *buf, int len) stm->rp += count; } - if (count == len || stm->dead) + if (count == len || stm->error || stm->eof) return count; assert(stm->rp == stm->wp); @@ -22,9 +22,13 @@ fz_read(fz_stream *stm, unsigned char *buf, int len) n = stm->read(stm, stm->bp, stm->ep - stm->bp); if (n < 0) { - stm->dead = 1; + stm->error = 1; return fz_rethrow(n, "read error"); } + else if (n == 0) + { + stm->eof = 1; + } else if (n > 0) { stm->rp = stm->bp; @@ -45,9 +49,13 @@ fz_read(fz_stream *stm, unsigned char *buf, int len) n = stm->read(stm, buf + count, len - count); if (n < 0) { - stm->dead = 1; + stm->error = 1; return fz_rethrow(n, "read error"); } + else if (n == 0) + { + stm->eof = 1; + } else if (n > 0) { stm->pos += n; @@ -65,15 +73,19 @@ fz_fillbuffer(fz_stream *stm) assert(stm->rp == stm->wp); - if (stm->dead) + if (stm->error || stm->eof) return; n = stm->read(stm, stm->bp, stm->ep - stm->bp); if (n < 0) { - stm->dead = 1; + stm->error = 1; fz_catch(n, "read error; treating as end of file"); } + else if (n == 0) + { + stm->eof = 1; + } else if (n > 0) { stm->rp = stm->bp; @@ -161,8 +173,8 @@ fz_seek(fz_stream *stm, int offset, int whence) offset = fz_tell(stm) + offset; whence = 0; } - stm->seek(stm, offset, whence); + stm->eof = 0; } else if (whence != 2) { |