lbarnaud                Sun Apr 19 17:10:52 2009 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src/main       php_streams.h 
    /php-src/main/streams       cast.c streams.c 
    /php-src/ext/standard       file.c streamsfuncs.c 
  Log:
  MFH: Better fix for #47997
  
  
http://cvs.php.net/viewvc.cgi/php-src/main/php_streams.h?r1=1.103.2.1.2.10&r2=1.103.2.1.2.11&diff_format=u
Index: php-src/main/php_streams.h
diff -u php-src/main/php_streams.h:1.103.2.1.2.10 
php-src/main/php_streams.h:1.103.2.1.2.11
--- php-src/main/php_streams.h:1.103.2.1.2.10   Sun Apr 19 14:44:09 2009
+++ php-src/main/php_streams.h  Sun Apr 19 17:10:52 2009
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_streams.h,v 1.103.2.1.2.10 2009/04/19 14:44:09 lbarnaud Exp $ */
+/* $Id: php_streams.h,v 1.103.2.1.2.11 2009/04/19 17:10:52 lbarnaud Exp $ */
 
 #ifndef PHP_STREAMS_H
 #define PHP_STREAMS_H
@@ -416,13 +416,11 @@
  * Uses mmap if the src is a plain file and at offset 0 */
 #define PHP_STREAM_COPY_ALL            ((size_t)-1)
 
-#define PHP_STREAM_FAILURE             ((size_t)-1)
-
 BEGIN_EXTERN_C()
 PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, 
size_t maxlen STREAMS_DC TSRMLS_DC);
 #define php_stream_copy_to_stream(src, dest, maxlen)   
_php_stream_copy_to_stream((src), (dest), (maxlen) STREAMS_CC TSRMLS_CC)
-PHPAPI size_t _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, 
size_t maxlen STREAMS_DC TSRMLS_DC);
-#define php_stream_copy_to_stream_ex(src, dest, maxlen)        
_php_stream_copy_to_stream_ex((src), (dest), (maxlen) STREAMS_CC TSRMLS_CC)
+PHPAPI size_t _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, 
size_t maxlen, size_t *len STREAMS_DC TSRMLS_DC);
+#define php_stream_copy_to_stream_ex(src, dest, maxlen, len)   
_php_stream_copy_to_stream_ex((src), (dest), (maxlen), (len) STREAMS_CC 
TSRMLS_CC)
 
 
 /* read all data from stream and put into a buffer. Caller must free buffer 
when done.
http://cvs.php.net/viewvc.cgi/php-src/main/streams/cast.c?r1=1.12.2.1.2.4&r2=1.12.2.1.2.5&diff_format=u
Index: php-src/main/streams/cast.c
diff -u php-src/main/streams/cast.c:1.12.2.1.2.4 
php-src/main/streams/cast.c:1.12.2.1.2.5
--- php-src/main/streams/cast.c:1.12.2.1.2.4    Sun Apr 19 14:44:09 2009
+++ php-src/main/streams/cast.c Sun Apr 19 17:10:52 2009
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: cast.c,v 1.12.2.1.2.4 2009/04/19 14:44:09 lbarnaud Exp $ */
+/* $Id: cast.c,v 1.12.2.1.2.5 2009/04/19 17:10:52 lbarnaud Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -214,9 +214,9 @@
 
                        newstream = php_stream_fopen_tmpfile();
                        if (newstream) {
-                               size_t copied = 
php_stream_copy_to_stream_ex(stream, newstream, PHP_STREAM_COPY_ALL);
+                               int ret = php_stream_copy_to_stream_ex(stream, 
newstream, PHP_STREAM_COPY_ALL, NULL);
 
-                               if (copied == PHP_STREAM_FAILURE) {
+                               if (ret != SUCCESS) {
                                        php_stream_close(newstream);
                                } else {
                                        int retcode = 
php_stream_cast(newstream, castas | flags, ret, show_err);
@@ -327,7 +327,7 @@
        if (*newstream == NULL)
                return PHP_STREAM_FAILED;
 
-       if (php_stream_copy_to_stream_ex(origstream, *newstream, 
PHP_STREAM_COPY_ALL) == PHP_STREAM_FAILURE) {
+       if (php_stream_copy_to_stream_ex(origstream, *newstream, 
PHP_STREAM_COPY_ALL, NULL) != SUCCESS) {
                php_stream_close(*newstream);
                *newstream = NULL;
                return PHP_STREAM_CRITICAL;
http://cvs.php.net/viewvc.cgi/php-src/main/streams/streams.c?r1=1.82.2.6.2.35&r2=1.82.2.6.2.36&diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.82.2.6.2.35 
php-src/main/streams/streams.c:1.82.2.6.2.36
--- php-src/main/streams/streams.c:1.82.2.6.2.35        Sun Apr 19 14:44:09 2009
+++ php-src/main/streams/streams.c      Sun Apr 19 17:10:52 2009
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.82.2.6.2.35 2009/04/19 14:44:09 lbarnaud Exp $ */
+/* $Id: streams.c,v 1.82.2.6.2.36 2009/04/19 17:10:52 lbarnaud Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -1288,17 +1288,23 @@
        return len;
 }
 
-/* Returns the number of bytes moved, or PHP_STREAM_FAILURE on failure. */
-PHPAPI size_t _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, 
size_t maxlen STREAMS_DC TSRMLS_DC)
+/* Returns SUCCESS/FAILURE and sets *len to the number of bytes moved */
+PHPAPI size_t _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, 
size_t maxlen, size_t *len STREAMS_DC TSRMLS_DC)
 {
        char buf[CHUNK_SIZE];
        size_t readchunk;
        size_t haveread = 0;
        size_t didread;
+       size_t dummy;
        php_stream_statbuf ssbuf;
 
+       if (!len) {
+               len = &dummy;
+       }
+
        if (maxlen == 0) {
-               return 0;
+               *len = 0;
+               return SUCCESS;
        }
 
        if (maxlen == PHP_STREAM_COPY_ALL) {
@@ -1314,7 +1320,8 @@
                 && !S_ISCHR(ssbuf.sb.st_mode)
 #endif
                ) {
-                       return 0;
+                       *len = 0;
+                       return SUCCESS;
                }
        }
 
@@ -1328,14 +1335,16 @@
                        mapped = php_stream_write(dest, p, mapped);
 
                        php_stream_mmap_unmap(src);
+
+                       *len = mapped;
                        
                        /* we've got at least 1 byte to read. 
                         * less than 1 is an error */
 
                        if (mapped > 0) {
-                               return mapped;
+                               return SUCCESS;
                        }
-                       return PHP_STREAM_FAILURE;
+                       return FAILURE;
                }
        }
 
@@ -1359,7 +1368,8 @@
                        while(towrite) {
                                didwrite = php_stream_write(dest, writeptr, 
towrite);
                                if (didwrite == 0) {
-                                       return PHP_STREAM_FAILURE;
+                                       *len = haveread - (didread - towrite);
+                                       return FAILURE;
                                }
 
                                towrite -= didwrite;
@@ -1374,13 +1384,15 @@
                }
        }
 
+       *len = haveread;
+
        /* we've got at least 1 byte to read. 
         * less than 1 is an error */
 
        if (haveread > 0) {
-               return haveread;
+               return SUCCESS;
        }
-       return PHP_STREAM_FAILURE;
+       return FAILURE;
 }
 
 /* Returns the number of bytes moved.
@@ -1388,11 +1400,12 @@
  * Deprecated in favor of php_stream_copy_to_stream_ex() */
 PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, 
size_t maxlen STREAMS_DC TSRMLS_DC)
 {
-       size_t ret = _php_stream_copy_to_stream_ex(src, dest, maxlen 
STREAMS_REL_CC TSRMLS_CC);
-       if (ret == 0 && maxlen != 0) {
+       size_t len;
+       int ret = _php_stream_copy_to_stream_ex(src, dest, maxlen, &len 
STREAMS_REL_CC TSRMLS_CC);
+       if (ret == SUCCESS && len == 0 && maxlen != 0) {
                return 1;
        }
-       return ret;
+       return len;
 }
 /* }}} */
 
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.409.2.6.2.39&r2=1.409.2.6.2.40&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.409.2.6.2.39 
php-src/ext/standard/file.c:1.409.2.6.2.40
--- php-src/ext/standard/file.c:1.409.2.6.2.39  Sun Apr 19 14:44:09 2009
+++ php-src/ext/standard/file.c Sun Apr 19 17:10:52 2009
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: file.c,v 1.409.2.6.2.39 2009/04/19 14:44:09 lbarnaud Exp $ */
+/* $Id: file.c,v 1.409.2.6.2.40 2009/04/19 17:10:52 lbarnaud Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -629,12 +629,15 @@
        }
 
        switch (Z_TYPE_P(data)) {
-               case IS_RESOURCE:
-                       numbytes = (int) 
php_stream_copy_to_stream_ex(srcstream, stream, PHP_STREAM_COPY_ALL);
-                       if ((size_t)numbytes == PHP_STREAM_FAILURE) {
+               case IS_RESOURCE: {
+                       size_t len;
+                       if (php_stream_copy_to_stream_ex(srcstream, stream, 
PHP_STREAM_COPY_ALL, &len) != SUCCESS) {
                                numbytes = -1;
+                       } else {
+                               numbytes = len;
                        }
                        break;
+               }
                case IS_NULL:
                case IS_LONG:
                case IS_DOUBLE:
@@ -1839,7 +1842,7 @@
        deststream = php_stream_open_wrapper(dest, "wb", ENFORCE_SAFE_MODE | 
REPORT_ERRORS, NULL);
 
        if (srcstream && deststream) {
-               ret = php_stream_copy_to_stream_ex(srcstream, deststream, 
PHP_STREAM_COPY_ALL) == PHP_STREAM_FAILURE ? FAILURE : SUCCESS;
+               ret = php_stream_copy_to_stream_ex(srcstream, deststream, 
PHP_STREAM_COPY_ALL, NULL);
        }
        if (srcstream) {
                php_stream_close(srcstream);
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/streamsfuncs.c?r1=1.58.2.6.2.32&r2=1.58.2.6.2.33&diff_format=u
Index: php-src/ext/standard/streamsfuncs.c
diff -u php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.32 
php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.33
--- php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.32   Sun Apr 19 14:44:09 2009
+++ php-src/ext/standard/streamsfuncs.c Sun Apr 19 17:10:52 2009
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: streamsfuncs.c,v 1.58.2.6.2.32 2009/04/19 14:44:09 lbarnaud Exp $ */
+/* $Id: streamsfuncs.c,v 1.58.2.6.2.33 2009/04/19 17:10:52 lbarnaud Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -437,7 +437,8 @@
        php_stream *src, *dest;
        zval *zsrc, *zdest;
        long maxlen = PHP_STREAM_COPY_ALL, pos = 0;
-       size_t ret;
+       size_t len;
+       int ret;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|ll", &zsrc, 
&zdest, &maxlen, &pos) == FAILURE) {
                RETURN_FALSE;
@@ -451,12 +452,12 @@
                RETURN_FALSE;
        }
 
-       ret = php_stream_copy_to_stream_ex(src, dest, maxlen);
+       ret = php_stream_copy_to_stream_ex(src, dest, maxlen, &len);
 
-       if (ret == PHP_STREAM_FAILURE) {
+       if (ret != SUCCESS) {
                RETURN_FALSE;
        }
-       RETURN_LONG(ret);
+       RETURN_LONG(len);
 }
 /* }}} */
 

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

Reply via email to