comparison src/os_win32.c @ 14567:7267c0d910fe v8.1.0297

patch 8.1.0297: MS-Windows: tests fail, Vim crashes commit https://github.com/vim/vim/commit/cea1f9ec5256755ad119526fea2ef6811f7b53cd Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 19 14:38:42 2018 +0200 patch 8.1.0297: MS-Windows: tests fail, Vim crashes Problem: MS-Windows: tests fail, Vim crashes. Solution: Fix long file name handling.
author Christian Brabandt <cb@256bit.org>
date Sun, 19 Aug 2018 14:45:04 +0200
parents 3ea4a48213e6
children 5e85d326d616
comparison
equal deleted inserted replaced
14566:427c57b41bc2 14567:7267c0d910fe
3107 mch_dirname( 3107 mch_dirname(
3108 char_u *buf, 3108 char_u *buf,
3109 int len) 3109 int len)
3110 { 3110 {
3111 char_u abuf[_MAX_PATH + 1]; 3111 char_u abuf[_MAX_PATH + 1];
3112 DWORD lfnlen;
3112 3113
3113 /* 3114 /*
3114 * Originally this was: 3115 * Originally this was:
3115 * return (getcwd(buf, len) != NULL ? OK : FAIL); 3116 * return (getcwd(buf, len) != NULL ? OK : FAIL);
3116 * But the Win32s known bug list says that getcwd() doesn't work 3117 * But the Win32s known bug list says that getcwd() doesn't work
3122 WCHAR wbuf[_MAX_PATH + 1]; 3123 WCHAR wbuf[_MAX_PATH + 1];
3123 3124
3124 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0) 3125 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0)
3125 { 3126 {
3126 WCHAR wcbuf[_MAX_PATH + 1]; 3127 WCHAR wcbuf[_MAX_PATH + 1];
3127 char_u *p; 3128 char_u *p = NULL;
3128 3129
3129 if (GetLongPathNameW(wbuf, wcbuf, _MAX_PATH) != 0) 3130 if (GetLongPathNameW(wbuf, wcbuf, _MAX_PATH) != 0)
3131 {
3130 p = utf16_to_enc(wcbuf, NULL); 3132 p = utf16_to_enc(wcbuf, NULL);
3131 else 3133 if (STRLEN(p) >= (size_t)len)
3134 {
3135 // long path name is too long, fall back to short one
3136 vim_free(p);
3137 p = NULL;
3138 }
3139 }
3140 if (p == NULL)
3132 p = utf16_to_enc(wbuf, NULL); 3141 p = utf16_to_enc(wbuf, NULL);
3133 3142
3134 if (p != NULL) 3143 if (p != NULL)
3135 { 3144 {
3136 vim_strncpy(buf, p, len - 1); 3145 vim_strncpy(buf, p, len - 1);
3141 return FAIL; 3150 return FAIL;
3142 } 3151 }
3143 #endif 3152 #endif
3144 if (GetCurrentDirectory(len, (LPSTR)buf) == 0) 3153 if (GetCurrentDirectory(len, (LPSTR)buf) == 0)
3145 return FAIL; 3154 return FAIL;
3146 if (GetLongPathNameA((LPSTR)buf, (LPSTR)abuf, _MAX_PATH) == 0) 3155 lfnlen = GetLongPathNameA((LPCSTR)buf, (LPSTR)abuf, _MAX_PATH);
3147 // return the short path name 3156 if (lfnlen == 0 || lfnlen >= (DWORD)len)
3157 // Failed to get long path name or it's too long: fall back to the
3158 // short path name.
3148 return OK; 3159 return OK;
3149 3160
3150 vim_strncpy(abuf, buf, len - 1); 3161 STRCPY(buf, abuf);
3151 return OK; 3162 return OK;
3152 } 3163 }
3153 3164
3154 /* 3165 /*
3155 * Get file permissions for "name". 3166 * Get file permissions for "name".