To: vim-dev@vim.org Subject: Patch 6.3a.008 (extra) Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.3a.008 (extra) Problem: Windows 98: Some of the wide functions are not implemented, resulting in file I/O to fail. This depends on what Unicode support is installed. Solution: Handle the failure and fall back to non-wide functions. Files: src/os_win32.c *** ../vim-6.3a.007/src/os_win32.c Fri May 7 10:59:38 2004 --- src/os_win32.c Tue May 11 17:28:30 2004 *************** *** 2372,2377 **** --- 2372,2397 ---- * But the Win32s known bug list says that getcwd() doesn't work * so use the Win32 system call instead. */ + #ifdef FEAT_MBYTE + if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) + { + WCHAR wbuf[_MAX_PATH + 1]; + + if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0) + { + char_u *p = ucs2_to_enc(wbuf, NULL); + + if (p != NULL) + { + STRNCPY(buf, p, len - 1); + buf[len - 1] = NUL; + vim_free(p); + return OK; + } + } + /* Retry with non-wide function (for Windows 98). */ + } + #endif return (GetCurrentDirectory(len, buf) != 0 ? OK : FAIL); } *************** *** 2385,2395 **** char_u *name) { #ifdef FEAT_MBYTE ! /* Apparently GetFileAttributesW() exists on Win95/98/ME, but it doesn't ! * work. */ ! PlatformId(); ! if (g_PlatformId == VER_PLATFORM_WIN32_NT ! && enc_codepage >= 0 && (int)GetACP() != enc_codepage) { WCHAR *p = enc_to_ucs2(name, NULL); long n; --- 2405,2411 ---- char_u *name) { #ifdef FEAT_MBYTE ! if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) { WCHAR *p = enc_to_ucs2(name, NULL); long n; *************** *** 2398,2404 **** { n = (long)GetFileAttributesW(p); vim_free(p); ! return n; } } #endif --- 2414,2422 ---- { n = (long)GetFileAttributesW(p); vim_free(p); ! if (n >= 0 || GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) ! return n; ! /* Retry with non-wide function (for Windows 98). */ } } #endif *************** *** 2425,2431 **** { n = (long)SetFileAttributesW(p, perm); vim_free(p); ! return n ? OK : FAIL; } } #endif --- 2443,2451 ---- { n = (long)SetFileAttributesW(p, perm); vim_free(p); ! if (n || GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) ! return n ? OK : FAIL; ! /* Retry with non-wide function (for Windows 98). */ } } #endif *************** *** 2442,2459 **** #ifdef FEAT_MBYTE WCHAR *p = NULL; ! /* Apparently GetFileAttributesW() exists on Win95/98/ME, but it doesn't ! * work. */ ! PlatformId(); ! if (g_PlatformId == VER_PLATFORM_WIN32_NT ! && enc_codepage >= 0 && (int)GetACP() != enc_codepage) p = enc_to_ucs2(name, NULL); #endif #ifdef FEAT_MBYTE if (p != NULL) perm = GetFileAttributesW(p); ! else #endif perm = GetFileAttributes((char *)name); if (perm >= 0) --- 2462,2483 ---- #ifdef FEAT_MBYTE WCHAR *p = NULL; ! if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) p = enc_to_ucs2(name, NULL); #endif #ifdef FEAT_MBYTE if (p != NULL) + { perm = GetFileAttributesW(p); ! if (perm < 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) ! { ! /* Retry with non-wide function (for Windows 98). */ ! vim_free(p); ! p = NULL; ! } ! } ! if (p == NULL) #endif perm = GetFileAttributes((char *)name); if (perm >= 0) *************** *** 2461,2468 **** perm |= FILE_ATTRIBUTE_HIDDEN; #ifdef FEAT_MBYTE if (p != NULL) ! SetFileAttributesW(p, perm); ! else #endif SetFileAttributes((char *)name, perm); } --- 2485,2500 ---- perm |= FILE_ATTRIBUTE_HIDDEN; #ifdef FEAT_MBYTE if (p != NULL) ! { ! if (SetFileAttributesW(p, perm) == 0 ! && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) ! { ! /* Retry with non-wide function (for Windows 98). */ ! vim_free(p); ! p = NULL; ! } ! } ! if (p == NULL) #endif SetFileAttributes((char *)name, perm); } *************** *** 4033,4038 **** --- 4065,4071 ---- /* * this version of remove is not scared by a readonly (backup) file + * Return 0 for success, -1 for failure. */ int mch_remove(char_u *name) *************** *** 4049,4055 **** SetFileAttributesW(wn, FILE_ATTRIBUTE_NORMAL); n = DeleteFileW(wn) ? 0 : -1; vim_free(wn); ! return n; } } #endif --- 4082,4090 ---- SetFileAttributesW(wn, FILE_ATTRIBUTE_NORMAL); n = DeleteFileW(wn) ? 0 : -1; vim_free(wn); ! if (n == 0 || GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) ! return n; ! /* Retry with non-wide function (for Windows 98). */ } } #endif *************** *** 4180,4200 **** #ifdef FEAT_MBYTE WCHAR *wold = NULL; WCHAR *wnew = NULL; ! int retval = 0; if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) { wold = enc_to_ucs2((char_u *)pszOldFile, NULL); wnew = enc_to_ucs2((char_u *)pszNewFile, NULL); if (wold != NULL && wnew != NULL) - { retval = mch_wrename(wold, wnew); - vim_free(wold); - vim_free(wnew); - return retval; - } vim_free(wold); vim_free(wnew); } #endif --- 4215,4233 ---- #ifdef FEAT_MBYTE WCHAR *wold = NULL; WCHAR *wnew = NULL; ! int retval = -1; if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) { wold = enc_to_ucs2((char_u *)pszOldFile, NULL); wnew = enc_to_ucs2((char_u *)pszNewFile, NULL); if (wold != NULL && wnew != NULL) retval = mch_wrename(wold, wnew); vim_free(wold); vim_free(wnew); + if (retval == 0 || GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) + return retval; + /* Retry with non-wide function (for Windows 98). */ } #endif *************** *** 4325,4334 **** hFile = FindFirstFileW(TempNameW, &d); if (hFile == INVALID_HANDLE_VALUE) ! goto getout; (void)FindClose(hFile); } ! else #endif { char *pch; --- 4358,4374 ---- hFile = FindFirstFileW(TempNameW, &d); if (hFile == INVALID_HANDLE_VALUE) ! { ! if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) ! goto getout; ! ! /* Retry with non-wide function (for Windows 98). */ ! vim_free(wn); ! wn = NULL; ! } (void)FindClose(hFile); } ! if (wn == NULL) #endif { char *pch; *************** *** 4358,4367 **** if (wn != NULL) { if (!GetTempFileNameW(wn, L"VIM", 0, TempNameW)) ! goto getout; ! DeleteFileW(TempNameW); } ! else #endif { if (!GetTempFileName(n, "VIM", 0, TempName)) --- 4398,4415 ---- if (wn != NULL) { if (!GetTempFileNameW(wn, L"VIM", 0, TempNameW)) ! { ! if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) ! goto getout; ! ! /* Retry with non-wide function (for Windows 98). */ ! vim_free(wn); ! wn = NULL; ! } ! else ! DeleteFileW(TempNameW); } ! if (wn == NULL) #endif { if (!GetTempFileName(n, "VIM", 0, TempName)) *************** *** 4378,4385 **** | ((p & R_OK) ? GENERIC_READ : 0); #ifdef FEAT_MBYTE if (wn != NULL) hFile = CreateFileW(wn, am, 0, NULL, OPEN_EXISTING, 0, NULL); ! else #endif hFile = CreateFile(n, am, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) --- 4426,4442 ---- | ((p & R_OK) ? GENERIC_READ : 0); #ifdef FEAT_MBYTE if (wn != NULL) + { hFile = CreateFileW(wn, am, 0, NULL, OPEN_EXISTING, 0, NULL); ! if (hFile == INVALID_HANDLE_VALUE ! && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) ! { ! /* Retry with non-wide function (for Windows 98). */ ! vim_free(wn); ! wn = NULL; ! } ! } ! if (wn == NULL) #endif hFile = CreateFile(n, am, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) *** ../vim-6.3a.007/src/version.c Mon May 10 12:49:59 2004 --- src/version.c Tue May 11 17:48:56 2004 *************** *** 643,644 **** --- 643,646 ---- { /* Add new patch number below this line */ + /**/ + 8, /**/ -- hundred-and-one symptoms of being an internet addict: 248. You sign your letters with your e-mail address instead of your name. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///