Skip to content

Commit adf41ce

Browse files
committed
Windows platform compatibility added for the internal method init?(fileSystemRepresentation:flags:createMode:).
1 parent 87709dc commit adf41ce

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

Foundation/FileHandle.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -433,14 +433,16 @@ open class FileHandle : NSObject, NSSecureCoding {
433433
}
434434
}
435435
#endif
436-
437-
internal init?(fileSystemRepresentation: UnsafePointer<Int8>, flags: Int32, createMode: Int) {
438-
_fd = _CFOpenFileWithMode(fileSystemRepresentation, flags, mode_t(createMode))
439-
_closeOnDealloc = true
440-
super.init()
441-
if _fd < 0 {
442-
return nil
443-
}
436+
437+
internal convenience init?(fileSystemRepresentation: UnsafePointer<Int8>, flags: Int32, createMode: Int) {
438+
let fd = _CFOpenFileWithMode(fileSystemRepresentation, flags, mode_t(createMode))
439+
guard fd > 0 else { return nil }
440+
441+
#if os(Windows)
442+
self.init(handle: HANDLE(bitPattern: _get_osfhandle(fd))!, closeOnDealloc: true)
443+
#else
444+
self.init(fileDescriptor: fd, closeOnDealloc: true)
445+
#endif
444446
}
445447

446448
deinit {

Foundation/FileManager.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,18 +1737,14 @@ open class FileManager : NSObject {
17371737
guard let file1BytesRead = try? file1._readBytes(into: buffer1, length: bytesToRead), file1BytesRead == bytesToRead else {
17381738
return false
17391739
}
1740-
17411740
guard let file2BytesRead = try? file2._readBytes(into: buffer2, length: bytesToRead), file2BytesRead == bytesToRead else {
17421741
return false
17431742
}
1744-
17451743
guard memcmp(buffer1, buffer2, bytesToRead) == 0 else {
17461744
return false
17471745
}
1748-
17491746
bytesLeft -= Int64(bytesToRead)
17501747
}
1751-
17521748
return true
17531749
#endif
17541750
}

0 commit comments

Comments
 (0)