pollita Sun Sep 24 21:40:45 2006 UTC
Modified files:
/php-src/ext/standard file.c
Log:
PHP6 Updates for rmdir/mkdir/rename
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.456&r2=1.457&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.456 php-src/ext/standard/file.c:1.457
--- php-src/ext/standard/file.c:1.456 Sun Sep 24 20:33:14 2006
+++ php-src/ext/standard/file.c Sun Sep 24 21:40:44 2006
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.456 2006/09/24 20:33:14 pollita Exp $ */
+/* $Id: file.c,v 1.457 2006/09/24 21:40:44 pollita Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -1485,6 +1485,7 @@
/* {{{ php_mkdir
*/
+/* DEPRECATED APIs: Use php_stream_mkdir() instead */
PHPAPI int php_mkdir_ex(char *dir, long mode, int options TSRMLS_DC)
{
int ret;
@@ -1506,43 +1507,65 @@
}
/* }}} */
-/* {{{ proto bool mkdir(string pathname [, int mode [, bool recursive [,
resource context]]])
+/* {{{ proto bool mkdir(string pathname [, int mode [, bool recursive [,
resource context]]]) U
Create a directory */
PHP_FUNCTION(mkdir)
{
+ char *dir;
+ int dir_len;
+ zend_uchar dir_type;
zval *zcontext = NULL;
long mode = 0777;
- int dir_len;
zend_bool recursive = 0;
- char *dir;
php_stream_context *context;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lbr", &dir,
&dir_len, &mode, &recursive, &zcontext) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|lbr", &dir,
&dir_len, &dir_type, &mode, &recursive, &zcontext) == FAILURE) {
RETURN_FALSE;
}
context = php_stream_context_from_zval(zcontext, 0);
- RETURN_BOOL(php_stream_mkdir(dir, mode, (recursive ?
PHP_STREAM_MKDIR_RECURSIVE : 0) | REPORT_ERRORS, context));
+ if (dir_type == IS_UNICODE) {
+ if (FAILURE == php_stream_path_encode(NULL, &dir, &dir_len,
(UChar*)dir, dir_len, REPORT_ERRORS, context)) {
+ RETURN_FALSE;
+ }
+ }
+
+ RETVAL_BOOL(php_stream_mkdir(dir, mode, (recursive ?
PHP_STREAM_MKDIR_RECURSIVE : 0) | REPORT_ERRORS, context));
+
+ if (dir_type == IS_UNICODE) {
+ efree(dir);
+ }
}
/* }}} */
-/* {{{ proto bool rmdir(string dirname[, resource context])
+/* {{{ proto bool rmdir(string dirname[, resource context]) U
Remove a directory */
PHP_FUNCTION(rmdir)
{
char *dir;
+ int dir_len;
+ zend_uchar dir_type;
zval *zcontext = NULL;
php_stream_context *context;
- int dir_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &dir,
&dir_len, &zcontext) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|r", &dir,
&dir_len, &dir_type, &zcontext) == FAILURE) {
RETURN_FALSE;
}
context = php_stream_context_from_zval(zcontext, 0);
- RETURN_BOOL(php_stream_rmdir(dir, REPORT_ERRORS, context));
+ if (dir_type == IS_UNICODE) {
+ if (FAILURE == php_stream_path_encode(NULL, &dir, &dir_len,
(UChar*)dir, dir_len, REPORT_ERRORS, context)) {
+ RETURN_FALSE;
+ }
+ }
+
+ RETVAL_BOOL(php_stream_rmdir(dir, REPORT_ERRORS, context));
+
+ if (dir_type == IS_UNICODE) {
+ efree(dir);
+ }
}
/* }}} */
@@ -1639,40 +1662,65 @@
}
/* }}} */
-/* {{{ proto bool rename(string old_name, string new_name[, resource context])
+/* {{{ proto bool rename(string old_name, string new_name[, resource context])
U
Rename a file */
PHP_FUNCTION(rename)
{
char *old_name, *new_name;
int old_name_len, new_name_len;
+ zend_uchar old_name_type, new_name_type;
+ zend_uchar free_old_name = 0, free_new_name = 0;
zval *zcontext = NULL;
php_stream_wrapper *wrapper;
php_stream_context *context;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|r", &old_name,
&old_name_len, &new_name, &new_name_len, &zcontext) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "tt|r", &old_name,
&old_name_len, &old_name_type, &new_name, &new_name_len, &new_name_type,
&zcontext) == FAILURE) {
RETURN_FALSE;
}
+ context = php_stream_context_from_zval(zcontext, 0);
+ RETVAL_FALSE;
+
+ if (old_name_type == IS_UNICODE) {
+ if (FAILURE == php_stream_path_encode(NULL, &old_name,
&old_name_len, (UChar*)old_name, old_name_len, REPORT_ERRORS, context)) {
+ goto rename_cleanup;
+ }
+ free_old_name = 1;
+ }
+
wrapper = php_stream_locate_url_wrapper(old_name, NULL, 0 TSRMLS_CC);
if (!wrapper || !wrapper->wops) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to locate
stream wrapper");
- RETURN_FALSE;
+ goto rename_cleanup;
}
if (!wrapper->wops->rename) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s wrapper does
not support renaming", wrapper->wops->label ? wrapper->wops->label : "Source");
- RETURN_FALSE;
+ goto rename_cleanup;
+ }
+
+ if (new_name_type == IS_UNICODE) {
+ if (FAILURE == php_stream_path_encode(NULL, &new_name,
&new_name_len, (UChar*)new_name, new_name_len, REPORT_ERRORS, context)) {
+ goto rename_cleanup;
+ }
+ free_new_name = 1;
}
if (wrapper != php_stream_locate_url_wrapper(new_name, NULL, 0
TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot rename a
file across wrapper types");
- RETURN_FALSE;
+ goto rename_cleanup;
}
- context = php_stream_context_from_zval(zcontext, 0);
+ RETVAL_BOOL(wrapper->wops->rename(wrapper, old_name, new_name, 0,
context TSRMLS_CC));
- RETURN_BOOL(wrapper->wops->rename(wrapper, old_name, new_name, 0,
context TSRMLS_CC));
+rename_cleanup:
+ if (free_old_name) {
+ efree(old_name);
+ }
+ if (free_new_name) {
+ efree(new_name);
+ }
}
/* }}} */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php