Commit bfd69ee6 authored by Johannes Schriewer's avatar Johannes Schriewer

Bugfix: SEGFAULT when opening non-existing file

parent 9ef54652
......@@ -27,7 +27,7 @@ public class File {
private(set) public var path: Path?
/// take ownership of the file descriptor/pointer
private let closeWhenDeallocated: Bool
private var closeWhenDeallocated: Bool
/// File mode
public enum Mode:String {
......@@ -85,12 +85,13 @@ public class File {
openMode += "b"
}
self.path = path
self.closeWhenDeallocated = true
self.closeWhenDeallocated = false
self.fp = fopen(path.description, openMode)
if self.fp == nil {
throw errnoToError(errno: errno)
}
self.closeWhenDeallocated = true
}
/// Initialize with a file descriptor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment