lbarnaud Sun Apr 19 17:10:35 2009 UTC
Modified files: (Branch: PHP_5_3)
/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.4.2.9&r2=1.103.2.1.2.4.2.10&diff_format=u
Index: php-src/main/php_streams.h
diff -u php-src/main/php_streams.h:1.103.2.1.2.4.2.9
php-src/main/php_streams.h:1.103.2.1.2.4.2.10
--- php-src/main/php_streams.h:1.103.2.1.2.4.2.9 Sun Apr 19 13:46:47 2009
+++ php-src/main/php_streams.h Sun Apr 19 17:10:34 2009
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_streams.h,v 1.103.2.1.2.4.2.9 2009/04/19 13:46:47 lbarnaud Exp $ */
+/* $Id: php_streams.h,v 1.103.2.1.2.4.2.10 2009/04/19 17:10:34 lbarnaud Exp $
*/
#ifndef PHP_STREAMS_H
#define PHP_STREAMS_H
@@ -420,14 +420,12 @@
* 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()
ZEND_ATTRIBUTE_DEPRECATED
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.1.2.4&r2=1.12.2.1.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.1.2.4
php-src/main/streams/cast.c:1.12.2.1.2.1.2.5
--- php-src/main/streams/cast.c:1.12.2.1.2.1.2.4 Sun Apr 19 13:46:47 2009
+++ php-src/main/streams/cast.c Sun Apr 19 17:10:34 2009
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: cast.c,v 1.12.2.1.2.1.2.4 2009/04/19 13:46:47 lbarnaud Exp $ */
+/* $Id: cast.c,v 1.12.2.1.2.1.2.5 2009/04/19 17:10:34 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);
@@ -332,7 +332,7 @@
(*newstream)->open_lineno = origstream->open_lineno;
#endif
- 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.18.2.25&r2=1.82.2.6.2.18.2.26&diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.82.2.6.2.18.2.25
php-src/main/streams/streams.c:1.82.2.6.2.18.2.26
--- php-src/main/streams/streams.c:1.82.2.6.2.18.2.25 Sun Apr 19 13:46:47 2009
+++ php-src/main/streams/streams.c Sun Apr 19 17:10:34 2009
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streams.c,v 1.82.2.6.2.18.2.25 2009/04/19 13:46:47 lbarnaud Exp $ */
+/* $Id: streams.c,v 1.82.2.6.2.18.2.26 2009/04/19 17:10:34 lbarnaud Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -1297,17 +1297,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) {
@@ -1323,7 +1329,8 @@
&& !S_ISCHR(ssbuf.sb.st_mode)
#endif
) {
- return 0;
+ *len = 0;
+ return SUCCESS;
}
}
@@ -1337,14 +1344,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;
}
}
@@ -1369,7 +1378,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;
@@ -1384,13 +1394,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.
@@ -1399,11 +1411,12 @@
ZEND_ATTRIBUTE_DEPRECATED
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.28.2.30&r2=1.409.2.6.2.28.2.31&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.409.2.6.2.28.2.30
php-src/ext/standard/file.c:1.409.2.6.2.28.2.31
--- php-src/ext/standard/file.c:1.409.2.6.2.28.2.30 Sun Apr 19 13:46:46 2009
+++ php-src/ext/standard/file.c Sun Apr 19 17:10:34 2009
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.409.2.6.2.28.2.30 2009/04/19 13:46:46 lbarnaud Exp $ */
+/* $Id: file.c,v 1.409.2.6.2.28.2.31 2009/04/19 17:10:34 lbarnaud Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -626,12 +626,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:
@@ -1786,7 +1789,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.15.2.35&r2=1.58.2.6.2.15.2.36&diff_format=u
Index: php-src/ext/standard/streamsfuncs.c
diff -u php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.15.2.35
php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.15.2.36
--- php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.15.2.35 Sun Apr 19
13:46:46 2009
+++ php-src/ext/standard/streamsfuncs.c Sun Apr 19 17:10:35 2009
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streamsfuncs.c,v 1.58.2.6.2.15.2.35 2009/04/19 13:46:46 lbarnaud Exp $
*/
+/* $Id: streamsfuncs.c,v 1.58.2.6.2.15.2.36 2009/04/19 17:10:35 lbarnaud Exp $
*/
#include "php.h"
#include "php_globals.h"
@@ -443,7 +443,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;
@@ -457,12 +458,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