]> granicus.if.org Git - php/commitdiff
Fix for Bug #22199 (fputs() + fgets() destroys readbuffer for non-seekable streams).
authorWez Furlong <wez@php.net>
Thu, 13 Feb 2003 21:03:25 +0000 (21:03 +0000)
committerWez Furlong <wez@php.net>
Thu, 13 Feb 2003 21:03:25 +0000 (21:03 +0000)
main/streams.c

index b7385073f452e0e4d7661d76a2e46c530e4956ba..45eee090775838f69137b0c4433a8cf34ecbb823 100755 (executable)
@@ -863,14 +863,17 @@ PHPAPI size_t _php_stream_write(php_stream *stream, const char *buf, size_t coun
                        justwrote = stream->ops->write(stream, buf, towrite TSRMLS_CC);
                }
                if (justwrote > 0) {
-                       stream->position += justwrote;
                        buf += justwrote;
                        count -= justwrote;
                        didwrite += justwrote;
                        
-                       /* FIXME: invalidate the whole readbuffer */
-                       stream->writepos = 0;
-                       stream->readpos = 0;
+                       /* Only screw with the buffer if we can seek, otherwise we lose data
+                        * buffered from fifos and sockets */
+                       if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
+                               stream->position += justwrote;
+                               stream->writepos = 0;
+                               stream->readpos = 0;
+                       }
                } else {
                        break;
                }