diff options
Diffstat (limited to 'ext/spl/spl_directory.c')
-rw-r--r-- | ext/spl/spl_directory.c | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 495314abe..8e04de7ce 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1523,29 +1523,25 @@ SPL_METHOD(RecursiveDirectoryIterator, getChildren) spl_filesystem_object_get_file_name(intern TSRMLS_CC); - if (SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_CURRENT_AS_PATHNAME)) { - RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); - } else { - MAKE_STD_ZVAL(zflags); - MAKE_STD_ZVAL(zpath); - ZVAL_LONG(zflags, intern->flags); - ZVAL_STRINGL(zpath, intern->file_name, intern->file_name_len, 1); - spl_instantiate_arg_ex2(Z_OBJCE_P(getThis()), &return_value, 0, zpath, zflags TSRMLS_CC); - zval_ptr_dtor(&zpath); - zval_ptr_dtor(&zflags); - - subdir = (spl_filesystem_object*)zend_object_store_get_object(return_value TSRMLS_CC); - if (subdir) { - if (intern->u.dir.sub_path && intern->u.dir.sub_path[0]) { - subdir->u.dir.sub_path_len = spprintf(&subdir->u.dir.sub_path, 0, "%s%c%s", intern->u.dir.sub_path, slash, intern->u.dir.entry.d_name); - } else { - subdir->u.dir.sub_path_len = strlen(intern->u.dir.entry.d_name); - subdir->u.dir.sub_path = estrndup(intern->u.dir.entry.d_name, subdir->u.dir.sub_path_len); - } - subdir->info_class = intern->info_class; - subdir->file_class = intern->file_class; - subdir->oth = intern->oth; + MAKE_STD_ZVAL(zflags); + MAKE_STD_ZVAL(zpath); + ZVAL_LONG(zflags, intern->flags); + ZVAL_STRINGL(zpath, intern->file_name, intern->file_name_len, 1); + spl_instantiate_arg_ex2(Z_OBJCE_P(getThis()), &return_value, 0, zpath, zflags TSRMLS_CC); + zval_ptr_dtor(&zpath); + zval_ptr_dtor(&zflags); + + subdir = (spl_filesystem_object*)zend_object_store_get_object(return_value TSRMLS_CC); + if (subdir) { + if (intern->u.dir.sub_path && intern->u.dir.sub_path[0]) { + subdir->u.dir.sub_path_len = spprintf(&subdir->u.dir.sub_path, 0, "%s%c%s", intern->u.dir.sub_path, slash, intern->u.dir.entry.d_name); + } else { + subdir->u.dir.sub_path_len = strlen(intern->u.dir.entry.d_name); + subdir->u.dir.sub_path = estrndup(intern->u.dir.entry.d_name, subdir->u.dir.sub_path_len); } + subdir->info_class = intern->info_class; + subdir->file_class = intern->file_class; + subdir->oth = intern->oth; } } /* }}} */ @@ -1911,6 +1907,9 @@ static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type TS } return SUCCESS; } + } else if (type == IS_BOOL) { + ZVAL_BOOL(writeobj, 1); + return SUCCESS; } if (readobj == writeobj) { zval_dtor(readobj); @@ -2644,19 +2643,26 @@ SPL_METHOD(SplFileObject, fgetcsv) } /* }}} */ -/* {{{ proto int SplFileObject::fputcsv(array fields, [string delimiter [, string enclosure]]) +/* {{{ proto int SplFileObject::fputcsv(array fields, [string delimiter [, string enclosure [, string escape]]]) Output a field array as a CSV line */ SPL_METHOD(SplFileObject, fputcsv) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); char delimiter = intern->u.file.delimiter, enclosure = intern->u.file.enclosure, escape = intern->u.file.escape; - char *delim = NULL, *enclo = NULL; - int d_len = 0, e_len = 0, ret; + char *delim = NULL, *enclo = NULL, *esc = NULL; + int d_len = 0, e_len = 0, esc_len = 0, ret; zval *fields = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ss", &fields, &delim, &d_len, &enclo, &e_len) == SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|sss", &fields, &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) { switch(ZEND_NUM_ARGS()) { + case 4: + if (esc_len != 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "escape must be a character"); + RETURN_FALSE; + } + escape = esc[0]; + /* no break */ case 3: if (e_len != 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character"); @@ -3031,6 +3037,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fputcsv, 0, 0, 1) ZEND_ARG_INFO(0, fields) ZEND_ARG_INFO(0, delimiter) ZEND_ARG_INFO(0, enclosure) + ZEND_ARG_INFO(0, escape) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_flock, 0, 0, 1) |