php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch 0001-Workaround-to-support-short-path-which-has-Unicode-c for Filesystem function related Bug #65358

Patch version 2013-10-04 09:23 UTC

Return to Bug #65358 | Download this patch
Patch Revisions:

Developer: ku@digitaldolphins.jp

From a561e4d7d893616ec37be706c6d80dfb8af2f590 Mon Sep 17 00:00:00 2001
From: "ku@digitaldolphins.jp" <ku@digitaldolphins.jp>
Date: Fri, 4 Oct 2013 18:05:33 +0900
Subject: [PATCH] Workaround to support short path which has Unicode character
 in long path.

---
 TSRM/tsrm_virtual_cwd.c | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c
index 3e211fa..d06c4d6 100644
--- a/TSRM/tsrm_virtual_cwd.c
+++ b/TSRM/tsrm_virtual_cwd.c
@@ -108,6 +108,29 @@ static int php_check_dots(const char *element, int n)
 	return (n != -1);
 }
 
+static int php_check_chr(const char *element, int n, char c)
+{
+	const char *fine = element;
+
+	if (n < 0)
+		n = strlen(element);
+
+	fine += n;
+
+	while (1) {
+		if (element >= fine)
+			return 0;
+		if (element[0] == c)
+			return 1;
+
+#ifdef TSRM_WIN32
+		element += (IsDBCSLeadByte(element) && element[1] != 0) ? 2 : 1;
+#else
+		element++;
+#endif
+	}
+}
+
 #define IS_DIRECTORY_UP(element, len) \
 	(len >= 2 && !php_check_dots(element, len))
 
@@ -1116,9 +1139,16 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
 				return -1;
 			}
 			if (save) {
-				i = strlen(data.cFileName);
-				memcpy(path+j, data.cFileName, i+1);
-				j += i;
+				if (php_check_chr(data.cFileName, -1, '?') != NULL && data.cAlternateFileName[0] != 0) {
+					i = strlen(data.cAlternateFileName);
+					memcpy(path+j, data.cAlternateFileName, i+1);
+					j += i;
+				}
+				else {
+					i = strlen(data.cFileName);
+					memcpy(path+j, data.cFileName, i+1);
+					j += i;
+				}
 			} else {
 				/* use the original file or directory name as it wasn't found */
 				memcpy(path+j, tmp+i, len-i+1);
-- 
1.7.11.msysgit.1

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 10 19:01:28 2024 UTC