wez Sun Oct 6 19:27:53 2002 EDT
Modified files:
/php4/main streams.c
Log:
Try to ensure that we return the number of bytes requested during fread().
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.97 php4/main/streams.c:1.98
--- php4/main/streams.c:1.97 Sat Oct 5 06:59:34 2002
+++ php4/main/streams.c Sun Oct 6 19:27:53 2002
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streams.c,v 1.97 2002/10/05 10:59:34 wez Exp $ */
+/* $Id: streams.c,v 1.98 2002/10/06 23:27:53 wez Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -501,61 +501,63 @@
PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size TSRMLS_DC)
{
- size_t toread, didread = 0;
+ size_t toread = 0, didread = 0;
- if (size == 0)
- return 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 */
- if (stream->writepos > stream->readpos) {
-
- toread = stream->writepos - stream->readpos;
- if (toread > size)
- toread = size;
-
- memcpy(buf, stream->readbuf + stream->readpos, toread);
- stream->readpos += toread;
- size -= toread;
- buf += toread;
- didread += toread;
- }
+ while (size > 0) {
- if (size == 0) {
- stream->position += didread;
+ /* 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 */
+ if (stream->writepos > stream->readpos) {
- if (didread == 0)
- stream->eof = 1;
-
- return didread;
- }
-
- if (stream->flags & PHP_STREAM_FLAG_NO_BUFFER || stream->chunk_size == 1) {
- if (stream->filterhead) {
- didread += stream->filterhead->fops->read(stream,
stream->filterhead,
- buf, size
- TSRMLS_CC);
- } else {
- didread += stream->ops->read(stream, buf, size TSRMLS_CC);
+ toread = stream->writepos - stream->readpos;
+ if (toread > size)
+ toread = size;
+
+ memcpy(buf, stream->readbuf + stream->readpos, toread);
+ stream->readpos += toread;
+ size -= toread;
+ buf += toread;
+ didread += toread;
}
- } else {
- php_stream_fill_read_buffer(stream, size TSRMLS_CC);
- if ((off_t)size > stream->writepos - stream->readpos)
- size = stream->writepos - stream->readpos;
-
- if (size) {
- memcpy(buf, stream->readbuf + stream->readpos, size);
- stream->readpos += size;
- didread += size;
+ if (size == 0) {
+ break;
+ }
+
+ if (stream->flags & PHP_STREAM_FLAG_NO_BUFFER || stream->chunk_size ==
+1) {
+ if (stream->filterhead) {
+ toread = stream->filterhead->fops->read(stream,
+stream->filterhead,
+ buf, size
+ TSRMLS_CC);
+ } else {
+ toread = stream->ops->read(stream, buf, size
+TSRMLS_CC);
+ }
+ } else {
+ php_stream_fill_read_buffer(stream, size TSRMLS_CC);
+
+ toread = stream->writepos - stream->readpos;
+ if (toread > size)
+ toread = size;
+
+ if (toread) {
+ memcpy(buf, stream->readbuf + stream->readpos, toread);
+ stream->readpos += toread;
+ }
+ }
+ if (toread > 0) {
+ didread += toread;
+ buf += toread;
+ size -= toread;
+ } else {
+ /* EOF, or temporary end of data (for non-blocking mode). */
+ break;
}
}
- stream->position += size;
- if (didread == 0)
- stream->eof = 1;
+ if (didread > 0)
+ stream->position += didread;
return didread;
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php