summaryrefslogtreecommitdiff
path: root/main/streams/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/streams/memory.c')
-rw-r--r--main/streams/memory.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/main/streams/memory.c b/main/streams/memory.c
index 09421ea49..81275f779 100644
--- a/main/streams/memory.c
+++ b/main/streams/memory.c
@@ -87,15 +87,19 @@ 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) {
- count = ms->fsize - ms->fpos;
+ if (ms->fpos == ms->fsize) {
stream->eof = 1;
- }
- if (count) {
- assert(ms->data!= NULL);
- assert(buf!= NULL);
- memcpy(buf, ms->data+ms->fpos, count);
- ms->fpos += count;
+ count = 0;
+ } else {
+ if (ms->fpos + count >= ms->fsize) {
+ count = ms->fsize - ms->fpos;
+ }
+ if (count) {
+ assert(ms->data!= NULL);
+ assert(buf!= NULL);
+ memcpy(buf, ms->data+ms->fpos, count);
+ ms->fpos += count;
+ }
}
return count;
}