php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #61315
Patch php54_dbcs_win_is_slash_2 revision 2012-03-08 07:38 UTC by ku at digitaldolphins dot jp
Patch php54_dbcs_win_is_slash_1 revision 2012-03-07 09:24 UTC by ku at digitaldolphins dot jp

Patch php54_dbcs_win_is_slash_1 for Filesystem function related Bug #61315

Patch version 2012-03-07 09:24 UTC

Return to Bug #61315 | Download this patch
This patch is obsolete

Obsoleted by patches:

Patch Revisions:

Developer: ku@digitaldolphins.jp

Index: tsrm_virtual_cwd.c
===================================================================
--- tsrm_virtual_cwd.c	(revision 323987)
+++ tsrm_virtual_cwd.c	(working copy)
@@ -767,7 +767,7 @@
 		}
 
 		i = len;
-		while (i > start && !IS_SLASH(path[i-1])) {
+		while (i > start && !IS_SLASH_PI(path, i-1)) {
 			i--;
 		}
 
@@ -789,20 +789,20 @@
 			j = tsrm_realpath_r(path, start, i-1, ll, t, use_realpath, 1, NULL TSRMLS_CC);
 			if (j > start) {
 				j--;
-				while (j > start && !IS_SLASH(path[j])) {
+				while (j > start && !IS_SLASH_PI(path, j)) {
 					j--;
 				}
 				if (!start) {
 					/* leading '..' must not be removed in case of relative path */
 					if (j == 0 && path[0] == '.' && path[1] == '.' &&
-							IS_SLASH(path[2])) {
+							IS_SLASH_PI(path, 2)) {
 						path[3] = '.';
 						path[4] = '.';
 						path[5] = DEFAULT_SLASH;
 						j = 5;
 					} else if (j > 0 &&
 							path[j+1] == '.' && path[j+2] == '.' &&
-							IS_SLASH(path[j+3])) {
+							IS_SLASH_PI(path, j+3)) {
 						j += 4;
 						path[j++] = '.';
 						path[j++] = '.';
@@ -1179,25 +1179,25 @@
 			int state_cwd_length = state->cwd_length;
 
 #ifdef TSRM_WIN32
-			if (IS_SLASH(path[0])) {
+			if (IS_SLASH_PI(path, 0)) {
 				if (state->cwd[1] == ':') {
 					/* Copy only the drive name */
 					state_cwd_length = 2;
 				} else if (IS_UNC_PATH(state->cwd, state->cwd_length)) {
 					/* Copy only the share name */
 					state_cwd_length = 2;
-					while (IS_SLASH(state->cwd[state_cwd_length])) {
+					while (IS_SLASH_PI(state->cwd, state_cwd_length)) {
 						state_cwd_length++;
 					}
 					while (state->cwd[state_cwd_length] &&
-							!IS_SLASH(state->cwd[state_cwd_length])) {
+							!IS_SLASH_PI(state->cwd, state_cwd_length)) {
 						state_cwd_length++;
 					}
-					while (IS_SLASH(state->cwd[state_cwd_length])) {
+					while (IS_SLASH_PI(state->cwd, state_cwd_length)) {
 						state_cwd_length++;
 					}
 					while (state->cwd[state_cwd_length] &&
-							!IS_SLASH(state->cwd[state_cwd_length])) {
+							!IS_SLASH_PI(state->cwd, state_cwd_length)) {
 						state_cwd_length++;
 					}
 				}
@@ -1218,7 +1218,7 @@
 		}
 	} else {
 #ifdef TSRM_WIN32
-		if (path_length > 2 && path[1] == ':' && !IS_SLASH(path[2])) {
+		if (path_length > 2 && path[1] == ':' && !IS_SLASH_PI(path, 2)) {
 			resolved_path[0] = path[0];
 			resolved_path[1] = ':';
 			resolved_path[2] = DEFAULT_SLASH;
@@ -1242,20 +1242,20 @@
 		resolved_path[0] = DEFAULT_SLASH;
 		resolved_path[1] = DEFAULT_SLASH;
 		start = 2;
-		while (!IS_SLASH(resolved_path[start])) {
+		while (!IS_SLASH_PI(resolved_path, start)) {
 			if (resolved_path[start] == 0) {
 				goto verify;
 			}
 			resolved_path[start] = toupper(resolved_path[start]);
-			start++;
+			start += _mbsinc(&resolved_path[start]) - &resolved_path[start];
 		}
 		resolved_path[start++] = DEFAULT_SLASH;
-		while (!IS_SLASH(resolved_path[start])) {
+		while (!IS_SLASH_PI(resolved_path, start)) {
 			if (resolved_path[start] == 0) {
 				goto verify;
 			}
 			resolved_path[start] = toupper(resolved_path[start]);
-			start++;
+			start += _mbsinc(&resolved_path[start]) - &resolved_path[start];
 		}
 		resolved_path[start++] = DEFAULT_SLASH;
 	} else if (IS_ABSOLUTE_PATH(resolved_path, path_length)) {
@@ -1268,17 +1268,17 @@
 	if (IS_ABSOLUTE_PATH(resolved_path, path_length)) {
 		/* skip VOLUME name */
 		start = 0;
-		while (start != ':') {
+		while (resolved_path[start] != ':') {
 			if (resolved_path[start] == 0) return -1;
 			start++;
 		}
 		start++;
-		if (!IS_SLASH(resolved_path[start])) return -1;
+		if (!IS_SLASH_PI(resolved_path, start)) return -1;
 		resolved_path[start++] = DEFAULT_SLASH;
 	}
 #endif
 
-	add_slash = (use_realpath != CWD_REALPATH) && path_length > 0 && IS_SLASH(resolved_path[path_length-1]);
+	add_slash = (use_realpath != CWD_REALPATH) && path_length > 0 && IS_SLASH_PI(resolved_path, path_length-1);
 	t = CWDG(realpath_cache_ttl) ? 0 : -1;
 	path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL TSRMLS_CC);
 
@@ -1290,7 +1290,7 @@
 	if (!start && !path_length) {
 		resolved_path[path_length++] = '.';
 	}
-	if (add_slash && path_length && !IS_SLASH(resolved_path[path_length-1])) {
+	if (add_slash && path_length && !IS_SLASH_PI(resolved_path, path_length-1)) {
 		if (path_length >= MAXPATHLEN-1) {
 			return -1;
 		}
@@ -1363,7 +1363,7 @@
 	if (length == 0) {
 		return 1; /* Can't cd to empty string */
 	}
-	while(--length >= 0 && !IS_SLASH(path[length])) {
+	while(--length >= 0 && !IS_SLASH_PI(path, length)) {
 	}
 
 	if (length == -1) {
Index: tsrm_virtual_cwd.h
===================================================================
--- tsrm_virtual_cwd.h	(revision 323987)
+++ tsrm_virtual_cwd.h	(working copy)
@@ -63,6 +63,8 @@
 #define IS_SLASH(c)	((c) == '/' || (c) == '\\')
 #define IS_SLASH_P(c)	(*(c) == '/' || \
         (*(c) == '\\' && !IsDBCSLeadByte(*(c-1))))
+#define IS_SLASH_PI(c,i)	((c)[i] == '/' || \
+        ((c)[i] == '\\' && ((i) == 0 || !IsDBCSLeadByte((c)[i-1]))))
 
 /* COPY_WHEN_ABSOLUTE is 2 under Win32 because by chance both regular absolute paths
    in the file system and UNC paths need copying of two characters */
@@ -81,6 +83,7 @@
 #define DEFAULT_DIR_SEPARATOR	';'
 #define IS_SLASH(c)	((c) == '/' || (c) == '\\')
 #define IS_SLASH_P(c)	IS_SLASH(*(c))
+#define IS_SLASH_PI(c,i)	IS_SLASH((c)[i]) // untested!
 /* Colon indicates volume name, either first character should be forward slash or backward slash */
 #define IS_ABSOLUTE_PATH(path, len) \
     ((strchr(path, ':') != NULL) || ((len >= 1) && ((path[0] == '/') || (path[0] == '\\'))))
@@ -100,6 +103,7 @@
 
 #define IS_SLASH(c)	((c) == '/')
 #define IS_SLASH_P(c)	(*(c) == '/')
+#define IS_SLASH_PI(c,i)	((c)[i] == '/') // untested!
 
 #endif
 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 13:01:29 2024 UTC