Skip to content

Commit e33eb72

Browse files
committed
FileSystemRepresentation converted to UTF16 before opening file in Windows platform.
1 parent 5e020b8 commit e33eb72

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Foundation/FileHandle.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,15 @@ open class FileHandle : NSObject, NSSecureCoding {
444444
#endif
445445

446446
internal convenience init?(fileSystemRepresentation: UnsafePointer<Int8>, flags: Int32, createMode: Int) {
447+
#if os(Windows)
448+
var fd: Int = -1
449+
if let path = String(cString: fileSystemRepresentation).cString(using: .utf16) {
450+
fd = _CFOpenFileWithMode(path, flags, mode_t(createMode))
451+
}
452+
#else
447453
let fd = _CFOpenFileWithMode(fileSystemRepresentation, flags, mode_t(createMode))
454+
#endif
448455
guard fd > 0 else { return nil }
449-
450456
self.init(fileDescriptor: fd, closeOnDealloc: true)
451457
}
452458

0 commit comments

Comments
 (0)