@@ -189,11 +189,29 @@ public struct CLTLogger : LogHandler {
189189 /* Is the write retried on interrupt?
190190 * We’ll assume yes, but we don’t and can’t know for sure
191191 * until FileHandle has been migrated to the open-source Foundation. */
192- #if canImport(Darwin)
193192 if #available( macOS 10 . 15 . 4 , tvOS 13 . 4 , iOS 13 . 4 , watchOS 6 . 2 , * ) {
193+ #if swift(>=5.2) || !canImport(Darwin)
194194 _ = try ? fh. write ( contentsOf: data)
195+ #else
196+ /* Let’s write “manullay” (FileHandle’s write(_:) method throws an ObjC exception in case of an error).
197+ * This code is copied below. */
198+ data. withUnsafeBytes { bytes in
199+ guard !bytes. isEmpty else {
200+ return
201+ }
202+ var written : Int = 0
203+ repeat {
204+ written += write (
205+ fh. fileDescriptor,
206+ bytes. baseAddress!. advanced ( by: written) ,
207+ bytes. count - written
208+ )
209+ } while written < bytes. count && ( errno == EINTR || errno == EAGAIN)
210+ }
211+ #endif
195212 } else {
196- /* Let’s write “manullay” (FileHandle’s write(_:) method throws an ObjC exception in case of an error. */
213+ /* Let’s write “manullay” (FileHandle’s write(_:) method throws an ObjC exception in case of an error).
214+ * This is a copy of the code just above. */
197215 data. withUnsafeBytes { bytes in
198216 guard !bytes. isEmpty else {
199217 return
@@ -208,9 +226,6 @@ public struct CLTLogger : LogHandler {
208226 } while written < bytes. count && ( errno == EINTR || errno == EAGAIN)
209227 }
210228 }
211- #else
212- _ = try ? fh. write ( contentsOf: data)
213- #endif
214229 }
215230 }
216231
0 commit comments