summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2001-12-30 22:25:49 +0000
committerwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2001-12-30 22:25:49 +0000
commite460b7b2cfec0614f2a68d5d935047f6ac7e4978 (patch)
tree3cffd12fe1c0be5efaf799d9d49fa23e8519cf0f
parent84c36c3e5f47e4225b9806978b35e9db18a8628f (diff)
downloadlibapr-e460b7b2cfec0614f2a68d5d935047f6ac7e4978.tar.gz
Doug MacEachern commented to me that perl, and some other apps, are
calling GetModuleName or other Win32 APIs to retrieve the relative or working path. Since some of these app authors have never observed an '\\?\D\Somepath" style unlimited-length filename, and retrieve as much when we spawn a process with that format, it's probably much safer to drop the extra decoration when we don't need it (because our filename is smaller than the Win32 MAX_PATH length.) So this patch does just that, and only uses "\\?\" notation when the filename is quite huge. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@62689 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--file_io/win32/open.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/file_io/win32/open.c b/file_io/win32/open.c
index 09ef76c9a..aad54853e 100644
--- a/file_io/win32/open.c
+++ b/file_io/win32/open.c
@@ -84,20 +84,34 @@ apr_status_t utf8_to_unicode_path(apr_wchar_t* retstr, apr_size_t retlen,
int srcremains = strlen(srcstr) + 1;
apr_wchar_t *t = retstr;
apr_status_t rv;
- if (srcstr[1] == ':' && (srcstr[2] == '/' || srcstr[2] == '\\')) {
- wcscpy (retstr, L"\\\\?\\");
- retlen -= 4;
- t += 4;
- }
- else if ((srcstr[0] == '/' || srcstr[0] == '\\')
- && (srcstr[1] == '/' || srcstr[1] == '\\')
- && (srcstr[2] != '?')) {
- /* Skip the slashes */
- srcstr += 2;
- srcremains -= 2;
- wcscpy (retstr, L"\\\\?\\UNC\\");
- retlen -= 8;
- t += 8;
+
+ /* This is correct, we don't twist the filename if it is will
+ * definately be shorter than MAX_PATH. It merits some
+ * performance testing to see if this has any effect, but there
+ * seem to be applications that get confused by the resulting
+ * Unicode \\?\ style file names, especially if they use argv[0]
+ * or call the Win32 API functions such as GetModuleName, etc.
+ * Not every application is prepared to handle such names.
+ *
+ * Note that a utf-8 name can never result in more wide chars
+ * than the original number of utf-8 narrow chars.
+ */
+ if (srcremains > MAX_PATH) {
+ if (srcstr[1] == ':' && (srcstr[2] == '/' || srcstr[2] == '\\')) {
+ wcscpy (retstr, L"\\\\?\\");
+ retlen -= 4;
+ t += 4;
+ }
+ else if ((srcstr[0] == '/' || srcstr[0] == '\\')
+ && (srcstr[1] == '/' || srcstr[1] == '\\')
+ && (srcstr[2] != '?')) {
+ /* Skip the slashes */
+ srcstr += 2;
+ srcremains -= 2;
+ wcscpy (retstr, L"\\\\?\\UNC\\");
+ retlen -= 8;
+ t += 8;
+ }
}
if (rv = conv_utf8_to_ucs2(srcstr, &srcremains, t, &retlen)) {