@@ -2644,26 +2644,45 @@ mch_isdir(char_u *name)
26442644 */
26452645 int
26462646mch_is_linked (char_u * fname )
2647+ {
2648+ BY_HANDLE_FILE_INFORMATION info ;
2649+
2650+ return win32_fileinfo (fname , & info ) == FILEINFO_OK
2651+ && info .nNumberOfLinks > 1 ;
2652+ }
2653+
2654+ /*
2655+ * Get the by-handle-file-information for "fname".
2656+ * Returns FILEINFO_OK when OK.
2657+ * returns FILEINFO_ENC_FAIL when enc_to_utf16() failed.
2658+ * Returns FILEINFO_READ_FAIL when CreateFile() failed.
2659+ * Returns FILEINFO_INFO_FAIL when GetFileInformationByHandle() failed.
2660+ */
2661+ int
2662+ win32_fileinfo (char_u * fname , BY_HANDLE_FILE_INFORMATION * info )
26472663{
26482664 HANDLE hFile ;
2649- int res = 0 ;
2650- BY_HANDLE_FILE_INFORMATION inf ;
2665+ int res = FILEINFO_READ_FAIL ;
26512666#ifdef FEAT_MBYTE
26522667 WCHAR * wn = NULL ;
26532668
26542669 if (enc_codepage >= 0 && (int )GetACP () != enc_codepage )
2670+ {
26552671 wn = enc_to_utf16 (fname , NULL );
2672+ if (wn == NULL )
2673+ res = FILEINFO_ENC_FAIL ;
2674+ }
26562675 if (wn != NULL )
26572676 {
26582677 hFile = CreateFileW (wn , /* file name */
26592678 GENERIC_READ , /* access mode */
2660- 0 , /* share mode */
2679+ FILE_SHARE_READ | FILE_SHARE_WRITE , /* share mode */
26612680 NULL , /* security descriptor */
26622681 OPEN_EXISTING , /* creation disposition */
2663- 0 , /* file attributes */
2682+ FILE_FLAG_BACKUP_SEMANTICS , /* file attributes */
26642683 NULL ); /* handle to template file */
26652684 if (hFile == INVALID_HANDLE_VALUE
2666- && GetLastError () == ERROR_CALL_NOT_IMPLEMENTED )
2685+ && GetLastError () == ERROR_CALL_NOT_IMPLEMENTED )
26672686 {
26682687 /* Retry with non-wide function (for Windows 98). */
26692688 vim_free (wn );
@@ -2674,17 +2693,18 @@ mch_is_linked(char_u *fname)
26742693#endif
26752694 hFile = CreateFile (fname , /* file name */
26762695 GENERIC_READ , /* access mode */
2677- 0 , /* share mode */
2696+ FILE_SHARE_READ | FILE_SHARE_WRITE , /* share mode */
26782697 NULL , /* security descriptor */
26792698 OPEN_EXISTING , /* creation disposition */
2680- 0 , /* file attributes */
2699+ FILE_FLAG_BACKUP_SEMANTICS , /* file attributes */
26812700 NULL ); /* handle to template file */
26822701
26832702 if (hFile != INVALID_HANDLE_VALUE )
26842703 {
2685- if (GetFileInformationByHandle (hFile , & inf ) != 0
2686- && inf .nNumberOfLinks > 1 )
2687- res = 1 ;
2704+ if (GetFileInformationByHandle (hFile , info ) != 0 )
2705+ res = FILEINFO_OK ;
2706+ else
2707+ res = FILEINFO_INFO_FAIL ;
26882708 CloseHandle (hFile );
26892709 }
26902710
0 commit comments