Mercurial > vim
comparison src/os_mswin.c @ 7681:07cfa8fea697 v7.4.1139
commit https://github.com/vim/vim/commit/fce7b3d24fd18b1486e474e933a95f9090df9973
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 19 19:00:32 2016 +0100
patch 7.4.1139
Problem: MS-Windows: getftype() returns "file for symlink to directory.
Solution: Make it return "dir". (Ken Takata)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 19 Jan 2016 19:15:05 +0100 |
parents | beb67ef38f88 |
children | 6069f43cea4e |
comparison
equal
deleted
inserted
replaced
7680:4b72a6f11547 | 7681:07cfa8fea697 |
---|---|
504 #endif | 504 #endif |
505 | 505 |
506 static int | 506 static int |
507 stat_symlink_aware(const char *name, struct stat *stp) | 507 stat_symlink_aware(const char *name, struct stat *stp) |
508 { | 508 { |
509 #if defined(_MSC_VER) && _MSC_VER < 1700 | 509 #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__MINGW32__) |
510 /* Work around for VC10 or earlier. stat() can't handle symlinks properly. | 510 /* Work around for VC12 or earlier (and MinGW). stat() can't handle |
511 * symlinks properly. | |
511 * VC9 or earlier: stat() doesn't support a symlink at all. It retrieves | 512 * VC9 or earlier: stat() doesn't support a symlink at all. It retrieves |
512 * status of a symlink itself. | 513 * status of a symlink itself. |
513 * VC10: stat() supports a symlink to a normal file, but it doesn't support | 514 * VC10: stat() supports a symlink to a normal file, but it doesn't support |
514 * a symlink to a directory (always returns an error). */ | 515 * a symlink to a directory (always returns an error). |
516 * VC11 and VC12: stat() doesn't return an error for a symlink to a | |
517 * directory, but it doesn't set S_IFDIR flag. | |
518 * MinGW: Same as VC9. */ | |
515 WIN32_FIND_DATA findData; | 519 WIN32_FIND_DATA findData; |
516 HANDLE hFind, h; | 520 HANDLE hFind, h; |
517 DWORD attr = 0; | 521 DWORD attr = 0; |
518 BOOL is_symlink = FALSE; | 522 BOOL is_symlink = FALSE; |
519 | 523 |
538 { | 542 { |
539 int fd, n; | 543 int fd, n; |
540 | 544 |
541 fd = _open_osfhandle((OPEN_OH_ARGTYPE)h, _O_RDONLY); | 545 fd = _open_osfhandle((OPEN_OH_ARGTYPE)h, _O_RDONLY); |
542 n = _fstat(fd, (struct _stat*)stp); | 546 n = _fstat(fd, (struct _stat*)stp); |
547 if ((n == 0) && (attr & FILE_ATTRIBUTE_DIRECTORY)) | |
548 stp->st_mode = (stp->st_mode & ~S_IFREG) | S_IFDIR; | |
543 _close(fd); | 549 _close(fd); |
544 return n; | 550 return n; |
545 } | 551 } |
546 } | 552 } |
547 #endif | 553 #endif |
550 | 556 |
551 #ifdef FEAT_MBYTE | 557 #ifdef FEAT_MBYTE |
552 static int | 558 static int |
553 wstat_symlink_aware(const WCHAR *name, struct _stat *stp) | 559 wstat_symlink_aware(const WCHAR *name, struct _stat *stp) |
554 { | 560 { |
555 # if defined(_MSC_VER) && _MSC_VER < 1700 | 561 # if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__MINGW32__) |
556 /* Work around for VC10 or earlier. _wstat() can't handle symlinks properly. | 562 /* Work around for VC12 or earlier (and MinGW). _wstat() can't handle |
563 * symlinks properly. | |
557 * VC9 or earlier: _wstat() doesn't support a symlink at all. It retrieves | 564 * VC9 or earlier: _wstat() doesn't support a symlink at all. It retrieves |
558 * status of a symlink itself. | 565 * status of a symlink itself. |
559 * VC10: _wstat() supports a symlink to a normal file, but it doesn't | 566 * VC10: _wstat() supports a symlink to a normal file, but it doesn't |
560 * support a symlink to a directory (always returns an error). */ | 567 * support a symlink to a directory (always returns an error). |
568 * VC11 and VC12: _wstat() doesn't return an error for a symlink to a | |
569 * directory, but it doesn't set S_IFDIR flag. | |
570 * MinGW: Same as VC9. */ | |
561 int n; | 571 int n; |
562 BOOL is_symlink = FALSE; | 572 BOOL is_symlink = FALSE; |
563 HANDLE hFind, h; | 573 HANDLE hFind, h; |
564 DWORD attr = 0; | 574 DWORD attr = 0; |
565 WIN32_FIND_DATAW findDataW; | 575 WIN32_FIND_DATAW findDataW; |
585 { | 595 { |
586 int fd; | 596 int fd; |
587 | 597 |
588 fd = _open_osfhandle((OPEN_OH_ARGTYPE)h, _O_RDONLY); | 598 fd = _open_osfhandle((OPEN_OH_ARGTYPE)h, _O_RDONLY); |
589 n = _fstat(fd, stp); | 599 n = _fstat(fd, stp); |
600 if ((n == 0) && (attr & FILE_ATTRIBUTE_DIRECTORY)) | |
601 stp->st_mode = (stp->st_mode & ~S_IFREG) | S_IFDIR; | |
590 _close(fd); | 602 _close(fd); |
591 return n; | 603 return n; |
592 } | 604 } |
593 } | 605 } |
594 # endif | 606 # endif |