| 1 | /** |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. |
| 3 | * This file is part of the mingw-w64 runtime package. |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. |
| 5 | */ |
| 6 | |
| 7 | #include <sys/stat.h> |
| 8 | #include <windows.h> |
| 9 | #include "__mingw_fix_stat.h" |
| 10 | |
| 11 | int __mingw_fix_fstat_finish(int ret, int fd, unsigned short *mode) |
| 12 | { |
| 13 | /* msvcrt's _fstat fills S_IFREG for directories. Fix it to S_IFDIR. */ |
| 14 | BY_HANDLE_FILE_INFORMATION fi; |
| 15 | if (ret == 0 && S_ISREG(*mode) && GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &fi) && (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) |
| 16 | *mode = (*mode & ~S_IFMT) | S_IFDIR; |
| 17 | return ret; |
| 18 | } |