From 59d2ce8258a6d519fa8b9f7f636cf23c025bae2f Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Tue, 23 May 2006 22:31:25 +0000 Subject: [PATCH] - MFH Fix feof() --- .../tests/file/stream_rfc2397_007.phpt | 141 ++++++++++++++++++ main/streams/memory.c | 14 +- 2 files changed, 149 insertions(+), 6 deletions(-) create mode 100755 ext/standard/tests/file/stream_rfc2397_007.phpt diff --git a/ext/standard/tests/file/stream_rfc2397_007.phpt b/ext/standard/tests/file/stream_rfc2397_007.phpt new file mode 100755 index 0000000000..e4341526db --- /dev/null +++ b/ext/standard/tests/file/stream_rfc2397_007.phpt @@ -0,0 +1,141 @@ +--TEST-- +Stream: RFC2397 and seeking +--FILE-- + +===DONE=== + +--EXPECTF-- +===data:,012345=== +int(0) +bool(false) +===S:4,S=== +int(0) +int(4) +bool(false) +===GETC=== +string(1) "4" +int(5) +bool(false) +===GETC=== +string(1) "5" +int(6) +bool(true) +===REWIND=== +bool(true) +int(0) +bool(false) +===GETC=== +string(1) "0" +int(1) +bool(false) +===S:3,S=== +int(0) +int(3) +bool(false) +===S:1,C=== +int(0) +int(4) +bool(false) +===S:-2,C=== +int(0) +int(2) +bool(false) +===S:-10,C=== +int(-1) +bool(false) +bool(false) +===S:3,S=== +int(0) +int(3) +bool(false) +===S:10,C=== +int(-1) +bool(false) +bool(false) +===S:-1,E=== +int(0) +int(5) +bool(false) +===S:0,E=== +int(0) +int(6) +bool(false) +===S:1,E=== +int(-1) +bool(false) +bool(false) +===DONE=== diff --git a/main/streams/memory.c b/main/streams/memory.c index aa39128791..cda930fe2f 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -88,16 +88,15 @@ static size_t php_stream_memory_read(php_stream *stream, char *buf, size_t count php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract; assert(ms != NULL); - if (ms->fpos + count > ms->fsize) { + if (ms->fpos + count >= ms->fsize) { count = ms->fsize - ms->fpos; + stream->eof = 1; } if (count) { assert(ms->data!= NULL); assert(buf!= NULL); memcpy(buf, ms->data+ms->fpos, count); ms->fpos += count; - } else { - stream->eof = 1; } return count; } @@ -147,6 +146,7 @@ static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence, } else { ms->fpos = ms->fpos + offset; *newoffs = ms->fpos; + stream->eof = 0; return 0; } } else { @@ -157,6 +157,7 @@ static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence, } else { ms->fpos = ms->fpos + offset; *newoffs = ms->fpos; + stream->eof = 0; return 0; } } @@ -168,6 +169,7 @@ static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence, } else { ms->fpos = offset; *newoffs = ms->fpos; + stream->eof = 0; return 0; } case SEEK_END: @@ -182,6 +184,7 @@ static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence, } else { ms->fpos = ms->fsize + offset; *newoffs = ms->fpos; + stream->eof = 0; return 0; } default: @@ -359,9 +362,7 @@ static size_t php_stream_temp_read(php_stream *stream, char *buf, size_t count T got = php_stream_read(ts->innerstream, buf, count); - if (!got) { - stream->eof |= ts->innerstream->eof; - } + stream->eof = ts->innerstream->eof; return got; } @@ -418,6 +419,7 @@ static int php_stream_temp_seek(php_stream *stream, off_t offset, int whence, of } ret = php_stream_seek(ts->innerstream, offset, whence); *newoffs = php_stream_tell(ts->innerstream); + stream->eof = ts->innerstream->eof; return ret; } -- 2.40.0