cvs: php-src /ext/standard file.c
| From: | Sara Golemon | Date: | Mon, 02 Oct 2006 02:47:34 +0000 |
| Subject: | cvs: php-src /ext/standard file.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-40801@lists.php.net to get a copy of this message | ||
pollita Mon Oct 2 02:47:34 2006 UTC
Modified files:
/php-src/ext/standard file.c
Log:
Apply simplified path encoding to copy() and give it a context param.
Funnily enough, this makes the copy() implementation almost identical
to what it was back in PHP5.
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.458&r2=1.459&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.458 php-src/ext/standard/file.c:1.459
--- php-src/ext/standard/file.c:1.458 Mon Oct 2 02:24:29 2006
+++ php-src/ext/standard/file.c Mon Oct 2 02:47:34 2006
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.458 2006/10/02 02:24:29 pollita Exp $ */
+/* $Id: file.c,v 1.459 2006/10/02 02:47:34 pollita Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -1881,49 +1881,28 @@
}
/* }}} */
-/* {{{ proto bool copy(string source_file, string destination_file) U
+/* {{{ proto bool copy(string source_file, string destination_file[, resource context]) U
Copy a file */
PHP_FUNCTION(copy)
{
- char *source, *dest;
- int source_len, dest_len;
- zend_uchar source_type, dest_type;
- zend_uchar free_source = 0, free_dest = 0;
+ zval **source, **target, *zcontext = NULL;
+ php_stream_context *context;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "tt", &source, &source_len,
&source_type, &dest, &dest_len, &dest_type) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZ|r", &source, &target,
&zcontext) == FAILURE) {
return;
}
- /* Assume failure until success is known */
- RETVAL_FALSE;
-
- if (source_type == IS_UNICODE) {
- if (FAILURE == php_stream_path_encode(NULL, &source, &source_len, (UChar*)source,
source_len, REPORT_ERRORS, FG(default_context))) {
- goto copy_cleanup;
- }
- free_source = 1;
- }
- if (dest_type == IS_UNICODE) {
- if (FAILURE == php_stream_path_encode(NULL, &dest, &dest_len, (UChar*)dest, dest_len,
REPORT_ERRORS, FG(default_context))) {
- goto copy_cleanup;
- }
- free_dest = 1;
- }
-
- if (php_check_open_basedir(source TSRMLS_CC)) {
- goto copy_cleanup;
- }
-
- if (php_copy_file(source, dest TSRMLS_CC) == SUCCESS) {
- RETVAL_TRUE;
+ context = php_stream_context_from_zval(zcontext, 0);
+ if (FAILURE == php_stream_path_param_encode(source, NULL, NULL, REPORT_ERRORS, context) ||
+ FAILURE == php_stream_path_param_encode(target, NULL, NULL, REPORT_ERRORS, context) ||
+ 0 != php_check_open_basedir(Z_STRVAL_PP(source) TSRMLS_CC)) {
+ RETURN_FALSE;
}
-copy_cleanup:
- if (free_source) {
- efree(source);
- }
- if (free_dest) {
- efree(dest);
+ if (php_copy_file(Z_STRVAL_PP(source), Z_STRVAL_PP(target) TSRMLS_CC)==SUCCESS) {
+ RETURN_TRUE;
+ } else {
+ RETURN_FALSE;
}
}
/* }}} */