aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-12-13 19:02:48 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-12-13 19:08:38 +0100
commit154774ada290f0e55101da7db5995295f231890e (patch)
treebf705f92caf701d99a18fb04fa777d611e579d00
parentTunnelsManager: Fix race between multiple startActivation() calls (diff)
downloadwireguard-apple-154774ada290f0e55101da7db5995295f231890e.tar.xz
wireguard-apple-154774ada290f0e55101da7db5995295f231890e.zip
Simplify C strings
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--WireGuard/Shared/Logging/Logger.swift19
1 files changed, 6 insertions, 13 deletions
diff --git a/WireGuard/Shared/Logging/Logger.swift b/WireGuard/Shared/Logging/Logger.swift
index f8ef70a7..b8dbdfd4 100644
--- a/WireGuard/Shared/Logging/Logger.swift
+++ b/WireGuard/Shared/Logging/Logger.swift
@@ -12,9 +12,7 @@ public class Logger {
init(withFilePath filePath: String, withTag tag: String) {
self.tag = tag
- self.log = filePath.withCString { fileC -> OpaquePointer? in
- open_log(fileC)
- }
+ self.log = open_log(filePath)
if self.log == nil {
os_log("Cannot open log file for writing. Log will not be saved to file.", log: OSLog.default, type: .error)
}
@@ -22,20 +20,15 @@ public class Logger {
func log(message: String) {
guard let log = log else { return }
- String(format: "[%@] %@", tag, message.trimmingCharacters(in: .newlines)).withCString { messageC in
- write_msg_to_log(log, messageC)
- }
+ write_msg_to_log(log, String(format: "[%@] %@", tag, message.trimmingCharacters(in: .newlines)))
}
func writeLog(mergedWith otherLogFile: String, to targetFile: String) -> Bool {
guard let log = log else { return false }
- guard let other = otherLogFile.withCString({ otherC -> OpaquePointer? in
- return open_log(otherC)
- }) else { return false }
- defer { close_log(other) }
- return targetFile.withCString { fileC -> Bool in
- return write_logs_to_file(fileC, log, other) == 0
- }
+ guard let other = open_log(otherLogFile) else { return false }
+ let ret = write_logs_to_file(targetFile, log, other)
+ close_log(other)
+ return ret == 0
}
static func configureGlobal(withFilePath filePath: String?, withTag tag: String) {