pollita Fri Sep 22 18:42:33 2006 UTC Modified files: /php-src/ext/standard streamsfuncs.c Log: Update stream_get_contents() for PHP6 http://cvs.php.net/viewvc.cgi/php-src/ext/standard/streamsfuncs.c?r1=1.87&r2=1.88&diff_format=u Index: php-src/ext/standard/streamsfuncs.c diff -u php-src/ext/standard/streamsfuncs.c:1.87 php-src/ext/standard/streamsfuncs.c:1.88 --- php-src/ext/standard/streamsfuncs.c:1.87 Thu Sep 21 19:53:10 2006 +++ php-src/ext/standard/streamsfuncs.c Fri Sep 22 18:42:33 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streamsfuncs.c,v 1.87 2006/09/21 19:53:10 pollita Exp $ */ +/* $Id: streamsfuncs.c,v 1.88 2006/09/22 18:42:33 pollita Exp $ */ #include "php.h" #include "php_globals.h" @@ -390,15 +390,15 @@ } /* }}} */ -/* {{{ proto string stream_get_contents(resource source [, long maxlen [, long offset]]) +/* {{{ proto string stream_get_contents(resource source [, long maxlen [, long offset]]) U Reads all remaining bytes (or up to maxlen bytes) from a stream and returns them as a string. */ PHP_FUNCTION(stream_get_contents) { php_stream *stream; zval *zsrc; - long maxlen = PHP_STREAM_COPY_ALL, pos = 0; + long maxlen = PHP_STREAM_COPY_ALL, pos = 0, real_maxlen; int len; - char *contents = NULL; + void *contents = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|ll", &zsrc, &maxlen, &pos) == FAILURE) { RETURN_FALSE; @@ -411,12 +411,34 @@ RETURN_FALSE; } - if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) { - RETVAL_STRINGL(contents, len, 0); - } else if (len == 0) { - RETVAL_EMPTY_STRING(); + if (maxlen <= 0 || stream->readbuf_type == IS_STRING) { + real_maxlen = maxlen; } else { - RETVAL_FALSE; + /* Allows worst case scenario of each input char being turned into two UChars + * UTODO: Have this take converter into account, since many never generate surrogate pairs */ + real_maxlen = maxlen * 2; + } + + len = php_stream_copy_to_mem_ex(stream, stream->readbuf_type, &contents, real_maxlen, maxlen, 0); + + if (stream->readbuf_type == IS_STRING) { + if (len > 0) { + RETVAL_STRINGL(contents, len, 0); + } else { + if (contents) { + efree(contents); + } + RETVAL_EMPTY_STRING(); + } + } else { + if (len > 0) { + RETVAL_UNICODEL(contents, len, 0); + } else { + if (contents) { + efree(contents); + } + RETVAL_EMPTY_UNICODE(); + } } } /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php