import CSystem extension ArkSys { public struct File { /// Reads the entire contents of a file as a String. public static func readString(_ path: String) -> String? { guard let fp = fopen(path, "r") else { return nil } defer { fclose(fp) } var result = "" var buf = [CChar](repeating: 0, count: 256) while fgets(&buf, 256, fp) != nil { result += String(cString: buf) } return result } /// Writes a String to a file, overwriting existing contents. public static func writeString(_ path: String, content: String) -> Bool { guard let fp = fopen(path, "w") else { return false } defer { fclose(fp) } return fputs(content, fp) >= 0 } } }