wez             Tue Oct 15 12:04:47 2002 EDT

  Modified files:              
    /php4/main  streams.c 
  Log:
  Some buffer paranoia.
  Also, make feof() detection safer (ala recent changes to zlib extension).
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.105 php4/main/streams.c:1.106
--- php4/main/streams.c:1.105   Mon Oct 14 01:38:50 2002
+++ php4/main/streams.c Tue Oct 15 12:04:46 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.105 2002/10/14 05:38:50 wez Exp $ */
+/* $Id: streams.c,v 1.106 2002/10/15 16:04:46 wez Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -808,6 +808,10 @@
                        buf += justwrote;
                        count -= justwrote;
                        didwrite += justwrote;
+                       
+                       /* FIXME: invalidate the whole readbuffer */
+                       stream->writepos = 0;
+                       stream->readpos = 0;
                } else {
                        break;
                }
@@ -827,24 +831,26 @@
                return 0;
 
        /* handle the case where we are in the buffer */
-       switch(whence) {
-               case SEEK_CUR:
-                       if (offset > 0 && offset < stream->writepos - stream->readpos) 
{
-                               stream->readpos += offset;
-                               stream->position += offset;
-                               stream->eof = 0;
-                               return 0;
-                       }
-                       break;
-               case SEEK_SET:
-                       if (offset > stream->position &&
-                                       offset < stream->position + stream->writepos - 
stream->readpos) {
-                               stream->readpos += offset - stream->position;
-                               stream->position = offset;
-                               stream->eof = 0;
-                               return 0;
-                       }
-                       break;
+       if ((stream->flags & PHP_STREAM_FLAG_NO_BUFFER) == 0) {
+               switch(whence) {
+                       case SEEK_CUR:
+                               if (offset > 0 && offset < stream->writepos - 
+stream->readpos) {
+                                       stream->readpos += offset;
+                                       stream->position += offset;
+                                       stream->eof = 0;
+                                       return 0;
+                               }
+                               break;
+                       case SEEK_SET:
+                               if (offset > stream->position &&
+                                               offset < stream->position + 
+stream->writepos - stream->readpos) {
+                                       stream->readpos += offset - stream->position;
+                                       stream->position = offset;
+                                       stream->eof = 0;
+                                       return 0;
+                               }
+                               break;
+               }
        }
        
        /* invalidate the buffer contents */
@@ -1286,7 +1292,7 @@
 
                ret = fread(buf, 1, count, data->file);
 
-               if (ret == 0 && feof(data->file))
+               if (feof(data->file))
                        stream->eof = 1;
        }
        return ret;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to