pollita         Mon Oct  2 17:45:30 2006 UTC

  Modified files:              
    /php-src/ext/standard       dir.c 
  Log:
  Switch opendir/chroot/chdir to new path_param API and upgrade scandir() for 
PHP6
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/dir.c?r1=1.155&r2=1.156&diff_format=u
Index: php-src/ext/standard/dir.c
diff -u php-src/ext/standard/dir.c:1.155 php-src/ext/standard/dir.c:1.156
--- php-src/ext/standard/dir.c:1.155    Sat Sep 23 12:32:32 2006
+++ php-src/ext/standard/dir.c  Mon Oct  2 17:45:30 2006
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dir.c,v 1.155 2006/09/23 12:32:32 tony2001 Exp $ */
+/* $Id: dir.c,v 1.156 2006/10/02 17:45:30 pollita Exp $ */
 
 /* {{{ includes/startup/misc */
 
@@ -178,36 +178,32 @@
 /* {{{ internal functions */
 static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject)
 {
-       UChar *udir;
+       zval **ppdir;
+       UChar *udir = NULL;
        char *dir;
        int dir_len, udir_len;
-       zend_uchar dir_type;
        zval *zcontext = NULL;
        php_stream_context *context = NULL;
        php_stream *dirp;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|r", &dir, 
&dir_len, &dir_type, &zcontext) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|r", &ppdir, 
&zcontext) == FAILURE) {
                return;
        }
 
        RETVAL_FALSE;
 
-       /* Save for later */
-       udir = (UChar*)dir;
-       udir_len = dir_len;
-
-       if (zcontext) {
-               context = php_stream_context_from_zval(zcontext, 0);
+       if (createobject && Z_TYPE_PP(ppdir) == IS_UNICODE) {
+               /* Save for later */
+               udir = eustrndup(Z_USTRVAL_PP(ppdir), Z_USTRLEN_PP(ppdir));
+               udir_len = Z_USTRLEN_PP(ppdir);
        }
 
-       if (dir_type == IS_UNICODE) {
-               if (FAILURE == php_stream_path_encode(NULL, &dir, &dir_len, 
udir, udir_len, REPORT_ERRORS, context)) {
-                       goto opendir_cleanup;
-               }
+       context = php_stream_context_from_zval(zcontext, 0);
+       if (FAILURE == php_stream_path_param_encode(ppdir, &dir, &dir_len, 
REPORT_ERRORS, context)) {
+               goto opendir_cleanup;
        }
 
        dirp = php_stream_opendir(dir, REPORT_ERRORS, context);
-
        if (dirp == NULL) {
                goto opendir_cleanup;
        }
@@ -216,8 +212,11 @@
 
        if (createobject) {
                object_init_ex(return_value, dir_class_entry_ptr);
-               if (dir_type == IS_UNICODE) {
-                       add_property_unicodel(return_value, "path", udir, 
udir_len, 1);
+               if (udir) {
+                       add_property_unicodel(return_value, "path", udir, 
udir_len, 0);
+
+                       /* Avoid auto-cleanup */
+                       udir = NULL;
                } else {
                        add_property_stringl(return_value, "path", dir, 
dir_len, 1);
                }
@@ -228,8 +227,8 @@
        }
 
 opendir_cleanup:
-       if (dir_type == IS_UNICODE) {
-               efree(dir);
+       if (udir) {
+               efree(udir);
        }
 }
 /* }}} */
@@ -272,25 +271,16 @@
    Change root directory */
 PHP_FUNCTION(chroot)
 {
+       zval **ppstr;
        char *str;
        int ret, str_len;
-       zend_uchar str_type;
        
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &str, 
&str_len, &str_type) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &ppstr) == 
FAILURE ||
+               php_stream_path_param_encode(ppstr, &str, &str_len, 
REPORT_ERRORS, FG(default_context)) == FAILURE) {
                return;
        }
-
-       if (str_type == IS_UNICODE) {
-               if (FAILURE == php_stream_path_encode(NULL, &str, &str_len, 
(UChar*)str, str_len, REPORT_ERRORS, FG(default_context))) {
-                       RETURN_FALSE;
-               }
-       }
        
        ret = chroot(str);
-       if (str_type == IS_UNICODE) {
-               efree(str);
-       }
-       
        if (ret != 0) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s (errno %d)", 
strerror(errno), errno);
                RETURN_FALSE;
@@ -312,25 +302,16 @@
    Change the current directory */
 PHP_FUNCTION(chdir)
 {
+       zval **ppstr;
        char *str;
        int ret, str_len;
-       zend_uchar str_type;
        
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &str, 
&str_len, &str_type) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &ppstr) == 
FAILURE ||
+               php_stream_path_param_encode(ppstr, &str, &str_len, 
REPORT_ERRORS, FG(default_context)) == FAILURE) {
                return;
        }
 
-       if (str_type == IS_UNICODE) {
-               if (FAILURE == php_stream_path_encode(NULL, &str, &str_len, 
(UChar*)str, str_len, REPORT_ERRORS, FG(default_context))) {
-                       RETURN_FALSE;
-               }
-       }
-
        ret = VCWD_CHDIR(str);
-       if (str_type == IS_UNICODE) {
-               efree(str);
-       }
-       
        if (ret != 0) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s (errno %d)", 
strerror(errno), errno);
                RETURN_FALSE;
@@ -496,10 +477,11 @@
 /* }}} */
 #endif 
 
-/* {{{ proto array scandir(string dir [, int sorting_order [, resource 
context]])
+/* {{{ proto array scandir(string dir [, int sorting_order [, resource 
context]]) U
    List files & directories inside the specified path */
 PHP_FUNCTION(scandir)
 {
+       zval **ppdirn;
        char *dirn;
        int dirn_len;
        long flags = 0;
@@ -508,12 +490,13 @@
        zval *zcontext = NULL;
        php_stream_context *context = NULL;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lr", &dirn, 
&dirn_len, &flags, &zcontext) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|lr", &ppdirn, 
&flags, &zcontext) == FAILURE) {
                return;
        }
 
-       if (zcontext) {
-               context = php_stream_context_from_zval(zcontext, 0);
+       context = php_stream_context_from_zval(zcontext, 0);
+       if (FAILURE == php_stream_path_param_encode(ppdirn, &dirn, &dirn_len, 
REPORT_ERRORS, context)) {
+               RETURN_FALSE;
        }
 
        if (!flags) {
@@ -529,9 +512,19 @@
        array_init(return_value);
 
        for (i = 0; i < n; i++) {
-               add_next_index_rt_string(return_value, namelist[i], 0);
                if (UG(unicode)) {
-                       efree(namelist[i]);
+                       UChar *path;
+                       int path_len;
+
+                       if (SUCCESS == php_stream_path_decode(NULL, &path, 
&path_len, namelist[i], strlen(namelist[i]), REPORT_ERRORS, context)) {
+                               add_next_index_unicodel(return_value, path, 
path_len, 0);
+                               efree(namelist[i]);
+                       } else {
+                               /* Fallback on using the non-unicode version, 
path_decode will emit the warning for us */
+                               add_next_index_string(return_value, 
namelist[i], 0);
+                       }
+               } else {
+                       add_next_index_string(return_value, namelist[i], 0);
                }
        }
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to