wez Mon Sep 23 19:39:46 2002 EDT Modified files: /php4/main streams.c Log: Correct a buglet in the newly introduced buffer code. # Andi: this might have been the cause of that problem you mentioned. Index: php4/main/streams.c diff -u php4/main/streams.c:1.80 php4/main/streams.c:1.81 --- php4/main/streams.c:1.80 Mon Sep 23 15:10:33 2002 +++ php4/main/streams.c Mon Sep 23 19:39:46 2002 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.80 2002/09/23 19:10:33 wez Exp $ */ +/* $Id: streams.c,v 1.81 2002/09/23 23:39:46 wez Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -355,7 +355,8 @@ stream->readbuflen - stream->writepos TSRMLS_CC); } - if (justread == 0) + + if (justread <= 0) break; stream->writepos += justread; } @@ -363,15 +364,15 @@ PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size TSRMLS_DC) { - size_t avail, toread, didread = 0; + size_t toread, didread = 0; /* take from the read buffer first. * It is possible that a buffered stream was switched to non-buffered, so we * drain the remainder of the buffer before using the "raw" read mode for * the excess */ - avail = stream->writepos - stream->readpos; - if (avail) { - toread = avail; + if (stream->writepos > stream->readpos) { + + toread = stream->writepos - stream->readpos; if (toread > size) toread = size; @@ -379,7 +380,7 @@ stream->readpos += toread; size -= toread; buf += toread; - didread += size; + didread += toread; } if (size == 0) @@ -398,10 +399,12 @@ if ((off_t)size > stream->writepos - stream->readpos) size = stream->writepos - stream->readpos; - - memcpy(buf, stream->readbuf + stream->readpos, size); - stream->readpos += size; - didread += size; + + if (size) { + memcpy(buf, stream->readbuf + stream->readpos, size); + stream->readpos += size; + didread += size; + } } stream->position += size; return didread;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php