comparison src/os_win32.c @ 14561:3ea4a48213e6 v8.1.0294

patch 8.1.0294: MS-Windows: sometimes uses short directory name commit https://github.com/vim/vim/commit/3b9fcfcffab8f927a01877804fa6ac5bbca34c7a Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 18 20:20:27 2018 +0200 patch 8.1.0294: MS-Windows: sometimes uses short directory name Problem: MS-Windows: sometimes uses short directory name. Solution: Expand to long file name with correct caps. (Nobuhiro Takasaki, closes #3334)
author Christian Brabandt <cb@256bit.org>
date Sat, 18 Aug 2018 20:30:06 +0200
parents 3375a8cbb442
children 7267c0d910fe
comparison
equal deleted inserted replaced
14560:8413e66d00a1 14561:3ea4a48213e6
3106 int 3106 int
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];
3112
3111 /* 3113 /*
3112 * Originally this was: 3114 * Originally this was:
3113 * return (getcwd(buf, len) != NULL ? OK : FAIL); 3115 * return (getcwd(buf, len) != NULL ? OK : FAIL);
3114 * But the Win32s known bug list says that getcwd() doesn't work 3116 * But the Win32s known bug list says that getcwd() doesn't work
3115 * so use the Win32 system call instead. <Negri> 3117 * so use the Win32 system call instead. <Negri>
3119 { 3121 {
3120 WCHAR wbuf[_MAX_PATH + 1]; 3122 WCHAR wbuf[_MAX_PATH + 1];
3121 3123
3122 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0) 3124 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0)
3123 { 3125 {
3124 char_u *p = utf16_to_enc(wbuf, NULL); 3126 WCHAR wcbuf[_MAX_PATH + 1];
3127 char_u *p;
3128
3129 if (GetLongPathNameW(wbuf, wcbuf, _MAX_PATH) != 0)
3130 p = utf16_to_enc(wcbuf, NULL);
3131 else
3132 p = utf16_to_enc(wbuf, NULL);
3125 3133
3126 if (p != NULL) 3134 if (p != NULL)
3127 { 3135 {
3128 vim_strncpy(buf, p, len - 1); 3136 vim_strncpy(buf, p, len - 1);
3129 vim_free(p); 3137 vim_free(p);
3131 } 3139 }
3132 } 3140 }
3133 return FAIL; 3141 return FAIL;
3134 } 3142 }
3135 #endif 3143 #endif
3136 return (GetCurrentDirectory(len, (LPSTR)buf) != 0 ? OK : FAIL); 3144 if (GetCurrentDirectory(len, (LPSTR)buf) == 0)
3145 return FAIL;
3146 if (GetLongPathNameA((LPSTR)buf, (LPSTR)abuf, _MAX_PATH) == 0)
3147 // return the short path name
3148 return OK;
3149
3150 vim_strncpy(abuf, buf, len - 1);
3151 return OK;
3137 } 3152 }
3138 3153
3139 /* 3154 /*
3140 * Get file permissions for "name". 3155 * Get file permissions for "name".
3141 * Return mode_t or -1 for error. 3156 * Return mode_t or -1 for error.