Re: cvs: php4 /ext/standard streamsfuncs.c
| From: | Moriyoshi Koizumi | Date: | Sat, 19 Apr 2003 05:16:30 +0000 |
| Subject: | Re: cvs: php4 /ext/standard streamsfuncs.c | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-20376@lists.php.net to get a copy of this message | ||
IMO we can deprecate stream_copy_to_stream() and integrate the
implementation to copy().
Moriyoshi
"Sara Golemon" <php@alphaweb.net> wrote:
> pollita Fri Apr 18 22:47:16 2003 EDT
>
> Modified files:
> /php4/ext/standard streamsfuncs.c
> Log:
> Let stream_copy_to_stream() accept either stream resource or filename/url string. If
> filename, open the file, do the copy, then close it.
>
> Index: php4/ext/standard/streamsfuncs.c
> diff -u php4/ext/standard/streamsfuncs.c:1.10 php4/ext/standard/streamsfuncs.c:1.11
> --- php4/ext/standard/streamsfuncs.c:1.10 Wed Apr 16 10:30:25 2003
> +++ php4/ext/standard/streamsfuncs.c Fri Apr 18 22:47:16 2003
> @@ -17,7 +17,7 @@
> +----------------------------------------------------------------------+
> */
>
> -/* $Id: streamsfuncs.c,v 1.10 2003/04/16 14:30:25 moriyoshi Exp $ */
> +/* $Id: streamsfuncs.c,v 1.11 2003/04/19 02:47:16 pollita Exp $ */
>
> #include "php.h"
> #include "php_globals.h"
> @@ -267,18 +267,40 @@
> Reads up to maxlen bytes from source stream and writes them to dest stream. */
> PHP_FUNCTION(stream_copy_to_stream)
> {
> - php_stream *src, *dest;
> + php_stream *src = NULL, *dest = NULL;
> zval *zsrc, *zdest;
> - long maxlen = PHP_STREAM_COPY_ALL;
> + long maxlen = PHP_STREAM_COPY_ALL, copied;
>
> - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l", &zsrc, &zdest,
> &maxlen) == FAILURE) {
> + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|l", &zsrc, &zdest,
> &maxlen) == FAILURE) {
> RETURN_FALSE;
> }
>
> - php_stream_from_zval(src, &zsrc);
> - php_stream_from_zval(dest, &zdest);
> + php_stream_get_from_zval(src, &zsrc, "rb", USE_PATH | ENFORCE_SAFE_MODE |
> REPORT_ERRORS, NULL, NULL);
> + if (!src) {
> + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to access source stream");
> + RETURN_FALSE;
> + }
> +
> + php_stream_get_from_zval(dest, &zdest, "wb", ENFORCE_SAFE_MODE | REPORT_ERRORS,
> NULL, NULL);
> + if (!dest) {
> + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to access destination
> stream");
> + if (Z_TYPE_P(zsrc) == IS_STRING) {
> + php_stream_close(src);
> + }
> + RETURN_FALSE;
> + }
> +
> + copied = php_stream_copy_to_stream(src, dest, maxlen);
> +
> + if (Z_TYPE_P(zsrc) == IS_STRING) {
> + php_stream_close(src);
> + }
> +
> + if (Z_TYPE_P(zdest) == IS_STRING) {
> + php_stream_close(dest);
> + }
>
> - RETURN_LONG(php_stream_copy_to_stream(src, dest, maxlen));
> + RETURN_LONG(copied);
> }
> /* }}} */
>
>
>
>
> --
> PHP CVS Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>