     public static func openFileForMode(path: String, _ mode: String) throws -> File {
         let file = path.withCString({ pathPointer in mode.withCString({ fopen(pathPointer, $0) }) })
         guard file != nil else {
-            throw FileError.OpenFailed(descriptionOfLastError())
+            throw FileError.OpenFailed(Errno.description())
         }
         return File(file)
     }

    public static func currentWorkingDirectory() throws -> String {
        let path = getcwd(nil, 0)
        if path == nil {
            throw FileError.GetCurrentWorkingDirectoryFailed(descriptionOfLastError())
        }
        guard let result = String.fromCString(path) else {
            throw FileError.GetCurrentWorkingDirectoryFailed("Could not convert getcwd(...)'s result to String.")

        }
        try data.withUnsafeBufferPointer {
            if fwrite($0.baseAddress, 1, data.count, self.pointer) != data.count {
                throw FileError.WriteFailed(Errno.description())
            }
        }
    }
    
    public func seek(offset: Int) throws -> Void {
        if fseek(self.pointer, offset, SEEK_SET) != 0 {
            throw FileError.SeekFailed(Errno.description())
        }
    }

}

public func withNewFileOpenedForWriting<Result>(path: String, _ f: File throws -> Result) throws -> Result {
    return try withFileOpenedForMode(path, mode: "wb", f)
}

public func withFileOpenedForReading<Result>(path: String, _ f: File throws -> Result) throws -> Result {
    return try withFileOpenedForMode(path, mode: "rb", f)
}

public func withFileOpenedForWritingAndReading<Result>(path: String, _ f: File throws -> Result) throws -> Result {
    return try withFileOpenedForMode(path, mode: "r+b", f)
}

public func withFileOpenedForMode<Result>(path: String, mode: String, _ f: File throws -> Result) throws -> Result {
    let file = try File.openFileForMode(path, mode)
    defer {
        file.close()
    }
    return try f(file)
}

