File php-5.1.2-spl_directory.patch of Package php

--- ext/spl/spl_directory.c	2006/01/01 12:50:13	1.45.2.10
+++ ext/spl/spl_directory.c	2006/02/10 16:57:56	1.45.2.20
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_directory.c,v 1.45.2.10 2006/01/01 12:50:13 sniper Exp $ */
+/* $Id: spl_directory.c,v 1.45.2.20 2006/02/10 16:57:56 tony2001 Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -162,7 +162,7 @@
 			php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
 			break;
 		case SPL_FS_DIR:
-			intern->file_name_len = spprintf(&intern->file_name, 0, "%s/%s", intern->path, intern->u.dir.entry.d_name);
+			intern->file_name_len = spprintf(&intern->file_name, 0, "%s%c%s", intern->path, DEFAULT_SLASH, intern->u.dir.entry.d_name);
 			break;
 		}
 	}
@@ -176,7 +176,11 @@
 	intern->path_len = strlen(path);
 	intern->u.dir.dirp = php_stream_opendir(path, ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL);
 
-	if (intern->path_len && (path[intern->path_len-1] == '/' || path[intern->path_len-1] == '\\')) {
+	if (intern->path_len && (path[intern->path_len-1] == '/'
+#if defined(PHP_WIN32) || defined(NETWARE)
+		|| path[intern->path_len-1] == '\\'
+#endif
+	)) {
 		intern->path = estrndup(path, --intern->path_len);
 	} else {
 		intern->path = estrndup(path, intern->path_len);
@@ -279,7 +283,11 @@
 	intern->file_name_len = len;
 
 	p1 = strrchr(path, '/');
+#if defined(PHP_WIN32) || defined(NETWARE)
 	p2 = strrchr(path, '\\');
+#else
+	p2 = 0;
+#endif
 	if (p1 || p2) {
 		intern->path_len = (p1 > p2 ? p1 : p2) - path;
 	} else {
@@ -340,6 +348,8 @@
 		spl_filesystem_object_get_file_name(source TSRMLS_CC);
 		intern->file_name = estrndup(source->file_name, source->file_name_len);
 		intern->file_name_len = source->file_name_len;
+		intern->path = estrndup(source->path, source->path_len);
+		intern->path_len = source->path_len;
 		break;
 	case SPL_FS_FILE:
 		return_value->value.obj = spl_filesystem_object_new_ex(ce ? ce : source->file_class, &intern TSRMLS_CC);
@@ -368,6 +378,7 @@
 			Z_TYPE_P(return_value) = IS_NULL;
 			return NULL;
 		}
+		break;
 	case SPL_FS_DIR:	
 		php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
 		zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Operation not supported");
@@ -392,6 +403,12 @@
 		return;
 	}
 
+	if (!len) {
+		php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
+                zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Directory name must not be empty.");
+                return;
+	}
+
 	intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
 	spl_filesystem_dir_open(intern, path TSRMLS_CC);
 	intern->u.dir.is_recursive = instanceof_function(intern->std.ce, spl_ce_RecursiveDirectoryIterator TSRMLS_CC) ? 1 : 0;
@@ -690,6 +707,7 @@
 
 	spl_filesystem_object_create_type(ht, intern, SPL_FS_FILE, NULL, return_value TSRMLS_CC);
 }
+/* }}} */
 
 /* {{{ proto SplFileObject SplFileInfo::setFileClass([string class_name])
    Class to use in openFile() */
@@ -704,6 +722,7 @@
 
 	intern->file_class = ce;
 }
+/* }}} */
 
 /* {{{ proto SplFileObject SplFileInfo::setInfoClass([string class_name])
    Class to use in getFileInfo(), getPathInfo(), getSubPathInfo() */
@@ -718,6 +737,7 @@
 
 	intern->file_class = ce;
 }
+/* }}} */
 
 /* {{{ proto SplFileInfo SplFileInfo::getFileInfo([string $class_name])
    Get/copy file info */
@@ -732,6 +752,7 @@
 
 	spl_filesystem_object_create_type(ht, intern, SPL_FS_INFO, ce, return_value TSRMLS_CC);
 }
+/* }}} */
 
 /* {{{ proto SplFileInfo SplFileInfo::getPathInfo([string $class_name])
    Get/copy file info */
@@ -746,6 +767,7 @@
 
 	spl_filesystem_object_create_info(intern, intern->path, intern->path_len, 1, ce, return_value TSRMLS_CC);
 }
+/* }}} */
 
 /* {{{ proto void RecursiveDirectoryIterator::__construct(string path [, int flags])
  Cronstructs a new dir iterator from a path. */
@@ -852,7 +874,7 @@
 	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/%s", intern->u.dir.sub_path, intern->u.dir.entry.d_name);
+			subdir->u.dir.sub_path_len = spprintf(&subdir->u.dir.sub_path, 0, "%s%c%s", intern->u.dir.sub_path, DEFAULT_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);
@@ -885,7 +907,7 @@
 	int len;
 
 	if (intern->u.dir.sub_path) {
-		len = spprintf(&sub_name, 0, "%s/%s", intern->u.dir.sub_path, intern->u.dir.entry.d_name);
+		len = spprintf(&sub_name, 0, "%s%c%s", intern->u.dir.sub_path, DEFAULT_SLASH, intern->u.dir.entry.d_name);
 		RETURN_STRINGL(sub_name, len, 0);
 	} else {
 		RETURN_STRING(intern->u.dir.entry.d_name, 1);
@@ -907,7 +929,7 @@
 	}
 
 	if (intern->u.dir.sub_path) {
-		len = spprintf(&sub_name, 0, "%s/%s", intern->u.dir.sub_path, intern->u.dir.entry.d_name);
+		len = spprintf(&sub_name, 0, "%s%c%s", intern->u.dir.sub_path, DEFAULT_SLASH, intern->u.dir.entry.d_name);
 		spl_filesystem_object_create_info(intern, sub_name, len, 0, ce, return_value TSRMLS_CC);
 	} else {
 		spl_filesystem_object_create_info(intern, intern->path, intern->path_len, 1, ce, return_value TSRMLS_CC);
@@ -1181,6 +1203,7 @@
 			return SUCCESS;
 		}
 	}
+	ZVAL_NULL(writeobj);
 	return FAILURE;
 }
 /* }}} */
@@ -1190,19 +1213,19 @@
 static
 ZEND_BEGIN_ARG_INFO(arginfo_info___construct, 0) 
 	ZEND_ARG_INFO(0, file_name)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_info_openFile, 0, 0, 0)
 	ZEND_ARG_INFO(0, open_mode)
 	ZEND_ARG_INFO(0, use_include_path)
 	ZEND_ARG_INFO(0, context)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_info_optinalFileClass, 0, 0, 0)
 	ZEND_ARG_INFO(0, class_name)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 /* the method table */
 /* each method can have its own parameters and visibility */
@@ -1238,7 +1261,7 @@
 static
 ZEND_BEGIN_ARG_INFO(arginfo_dir___construct, 0) 
 	ZEND_ARG_INFO(0, path)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 /* the method table */
 /* each method can have its own parameters and visibility */
@@ -1259,7 +1282,7 @@
 ZEND_BEGIN_ARG_INFO(arginfo_r_dir___construct, 0) 
 	ZEND_ARG_INFO(0, path)
 	ZEND_ARG_INFO(0, flags)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static zend_function_entry spl_RecursiveDirectoryIterator_functions[] = {
 	SPL_ME(RecursiveDirectoryIterator, __construct,   arginfo_r_dir___construct, ZEND_ACC_PUBLIC)
@@ -1383,7 +1406,11 @@
 	
 	if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == SUCCESS) {
 		p1 = strrchr(intern->file_name, '/');
+#if defined(PHP_WIN32) || defined(NETWARE)
 		p2 = strrchr(intern->file_name, '\\');
+#else
+		p2 = 0;
+#endif
 		if (p1 || p2) {
 			intern->path_len = (p1 > p2 ? p1 : p2) - intern->file_name;
 		} else {
@@ -1774,13 +1801,13 @@
 	char *str;
 	int str_len;
 	int ret;
-	long length;
+	long length = 0;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &length) == FAILURE) {
 		return;
 	}
 
-	if (ZEND_NUM_ARGS() < 2) {
+	if (ZEND_NUM_ARGS() > 1) {
 		str_len = MAX(0, MIN(length, str_len));
 	}
 	if (!str_len) {
@@ -1851,61 +1878,61 @@
 	ZEND_ARG_INFO(0, open_mode)
 	ZEND_ARG_INFO(0, use_include_path)
 	ZEND_ARG_INFO(0, context)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO(arginfo_file_object_setFlags, 0) 
 	ZEND_ARG_INFO(0, flags)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO(arginfo_file_object_setMaxLineLen, 0) 
 	ZEND_ARG_INFO(0, max_len)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fgetcsv, 0, 0, 0) 
 	ZEND_ARG_INFO(0, delimiter)
 	ZEND_ARG_INFO(0, enclosure)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_flock, 0, 0, 1) 
 	ZEND_ARG_INFO(0, operation)
-	ZEND_ARG_INFO(1, wouldblock])
-ZEND_END_ARG_INFO();
+	ZEND_ARG_INFO(1, wouldblock)
+ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fseek, 0, 0, 1) 
 	ZEND_ARG_INFO(0, pos)
 	ZEND_ARG_INFO(0, whence)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fgetss, 0, 0, 0) 
 	ZEND_ARG_INFO(0, allowable_tags)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fscanf, 0, 0, 1) 
 	ZEND_ARG_INFO(0, format)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fwrite, 0, 0, 1) 
 	ZEND_ARG_INFO(0, str)
 	ZEND_ARG_INFO(0, length)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_ftruncate, 0, 0, 1) 
 	ZEND_ARG_INFO(0, size)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_seek, 0, 0, 1) 
 	ZEND_ARG_INFO(0, line_pos)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static zend_function_entry spl_SplFileObject_functions[] = {
 	SPL_ME(SplFileObject, __construct,    arginfo_file_object___construct,   ZEND_ACC_PUBLIC)
@@ -1945,7 +1972,7 @@
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_temp_file_object___construct, 0, 0, 1)
 	ZEND_ARG_INFO(0, max_memory)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 
 static zend_function_entry spl_SplTempFileObject_functions[] = {
 	SPL_ME(SplTempFileObject, __construct, arginfo_temp_file_object___construct,  ZEND_ACC_PUBLIC)
openSUSE Build Service is sponsored by