Skip to content

Commit f4be1a8

Browse files
authored
Merge pull request #2268 from compnerd/pipe-shaped-files-are-odd
Foundation: avoid `GetFileInformationByHandle` on a pipe
2 parents f4c37de + e5e8f26 commit f4be1a8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Foundation/FileHandle.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,12 @@ open class FileHandle : NSObject {
221221
return NSData.NSDataReadResult(bytes: nil, length: 0, deallocator: nil)
222222
}
223223

224-
var fiFileInfo: BY_HANDLE_FILE_INFORMATION = BY_HANDLE_FILE_INFORMATION()
225-
if !GetFileInformationByHandle(_handle, &fiFileInfo) {
226-
throw _NSErrorWithWindowsError(GetLastError(), reading: true)
227-
}
224+
if GetFileType(_handle) == FILE_TYPE_DISK {
225+
var fiFileInfo: BY_HANDLE_FILE_INFORMATION = BY_HANDLE_FILE_INFORMATION()
226+
if !GetFileInformationByHandle(_handle, &fiFileInfo) {
227+
throw _NSErrorWithWindowsError(GetLastError(), reading: true)
228+
}
228229

229-
if fiFileInfo.dwFileAttributes & DWORD(FILE_ATTRIBUTE_NORMAL) == FILE_ATTRIBUTE_NORMAL {
230230
if options.contains(.alwaysMapped) {
231231
let hMapping: HANDLE =
232232
CreateFileMappingA(_handle, nil, DWORD(PAGE_READONLY), 0, 0, nil)

0 commit comments

Comments
 (0)