Prechádzať zdrojové kódy

Fixed the wrong usage of withCString reported at https://github.com/httpswift/swifter/issues/142, for Linux.

Damian Kołakowski 10 rokov pred
rodič
commit
b13b905fc7
1 zmenil súbory, kde vykonal 1 pridanie a 7 odobranie
  1. 1 7
      Sources/File.swift

+ 1 - 7
Sources/File.swift

@@ -34,13 +34,7 @@ public class File {
     }
     
     public static func openFileForMode(path: String, _ mode: String) throws -> File {
-        #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
+        let file = path.withCString({ pathPointer in mode.withCString({ fopen(pathPointer, $0) }) })
         guard file != nil else {
             throw FileError.OpenFailed(descriptionOfLastError())
         }