Hi,

A wrong file may be opened when enc=utf-8 on Windows.

E.g. (on Japanese Windows, the code page is cp932):

 echo foo>テ、.txt   " Create a file. The filename is '<C3><A4>.txt' in cp932.
 gvim --cmd "set enc=utf-8" ä.txt  " 'ä.txt' is '<C3><A4>.txt' in utf-8.

Opening a new empty file is expected, but the buffer contains "foo" which
means that "テ、.txt" is opened.
Currently, Vim uses a Wide function first, and if it fails, Vim may fallback
to an ANSI function. Actually it is needed only on Win9x.
If a Wide Win32 API fails, we should check the result of GetLastError() to
judge whether we should use an ANSI API. However, if a Wide C runtime function
fails, we should check g_PlatformId instead of GetLastError().

Attached fix-utf8-wrong-fallback.patch fixes this issue.
I also find the similar parts which should be fixed.
See fix-utf8-wrong-fallback-addition.patch.

Regards,
Ken Takata

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
# HG changeset patch
# Parent 469cbc5adff9dad48757d6932f11adcedb6f7875
diff --git a/src/os_mswin.c b/src/os_mswin.c
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -643,7 +643,7 @@
 	{
 	    n = wstat_symlink_aware(wp, stp);
 	    vim_free(wp);
-	    if (n >= 0)
+	    if ((g_PlatformId == VER_PLATFORM_WIN32_NT) || (n >= 0))
 		return n;
 	    /* Retry with non-wide function (for Windows 98). Can't use
 	     * GetLastError() here and it's unclear what errno gets set to if
diff --git a/src/os_win32.c b/src/os_win32.c
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -5999,7 +5999,7 @@
 	{
 	    f = _wopen(wn, flags, mode);
 	    vim_free(wn);
-	    if (f >= 0)
+	    if ((g_PlatformId == VER_PLATFORM_WIN32_NT) || (f >= 0))
 		return f;
 	    /* Retry with non-wide function (for Windows 98). Can't use
 	     * GetLastError() here and it's unclear what errno gets set to if
@@ -6050,7 +6050,7 @@
 	_set_fmode(oldMode);
 # endif
 
-	if (f != NULL)
+	if ((g_PlatformId == VER_PLATFORM_WIN32_NT) || (f != NULL))
 	    return f;
 	/* Retry with non-wide function (for Windows 98). Can't use
 	 * GetLastError() here and it's unclear what errno gets set to if
# HG changeset patch
# Parent c632365ae4d0228222387e09525b3195780bbbb2

diff --git a/src/os_mswin.c b/src/os_mswin.c
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -824,8 +824,8 @@
 	{
 	    n = _wchdir(p);
 	    vim_free(p);
-	    if (n == 0)
-		return 0;
+	    if ((g_PlatformId == VER_PLATFORM_WIN32_NT) || (n == 0))
+		return n;
 	    /* Retry with non-wide function (for Windows 98). */
 	}
     }
@@ -1951,8 +1951,7 @@
 
 shortcut_errorw:
 		vim_free(p);
-		if (hr == S_OK)
-		    goto shortcut_end;
+		goto shortcut_end;
 	    }
 	}
 	/* Retry with non-wide function (for Windows 98). */
diff --git a/src/os_win32.c b/src/os_win32.c
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -2842,6 +2842,8 @@
 		return OK;
 	    }
 	}
+	else if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
+	    return FAIL;
 	/* Retry with non-wide function (for Windows 98). */
     }
 #endif
@@ -2882,6 +2884,8 @@
 		return;
 	    }
 	}
+	else if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
+	    return;
 	/* Retry with non-wide function (for Windows 98). */
     }
 #endif
@@ -2931,6 +2935,8 @@
 		return OK;
 	    }
 	}
+	else if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
+	    return FAIL;
 	/* Retry with non-wide function (for Windows 98). */
     }
 #endif
@@ -2971,7 +2977,7 @@
 	{
 	    n = _wchmod(p, perm);
 	    vim_free(p);
-	    if (n == -1 && GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
+	    if (n == -1 && g_PlatformId == VER_PLATFORM_WIN32_NT)
 		return FAIL;
 	    /* Retry with non-wide function (for Windows 98). */
 	}

Raspunde prin e-mail lui