Browse Source

Fix raw pointer conversion of filename and mode through NSString and UTF8 encoding.

Mathieu Barnachon 10 năm trước cách đây
mục cha
commit
7c05f9e7d4
1 tập tin đã thay đổi với 7 bổ sung1 xóa
  1. 7 1
      Sources/File.swift

+ 7 - 1
Sources/File.swift

@@ -34,7 +34,13 @@ public class File {
     }
     
     public static func openFileForMode(path: String, _ mode: String) throws -> File {
-        let file = fopen(path.withCString({ $0 }), mode.withCString({ $0 }))
+        #if os(Linux)
+            let file = fopen(path.withCString({ $0 }), mode.withCString({ $0 }))
+        #else
+            let filename = UnsafePointer<Int8>((path as NSString).UTF8String)
+            let filemode = UnsafePointer<Int8>((mode as NSString).UTF8String)
+            let file = fopen(filename, filemode)
+        #endif
         guard file != nil else {
             throw FileError.OpenFailed(descriptionOfLastError())
         }