Skip to content

Commit 63a83c9

Browse files
committed
Fix compilation on Windows
1 parent 17a34a0 commit 63a83c9

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

Sources/CLTLogger.swift

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public struct CLTLogger : LogHandler {
192192
if #available(macOS 10.15.4, tvOS 13.4, iOS 13.4, watchOS 6.2, *) {
193193
#if swift(>=5.2) || !canImport(Darwin)
194194
_ = try? fh.write(contentsOf: data)
195-
#else
195+
#elseif !os(Windows)
196196
/* Let’s write “manually” (FileHandle’s write(_:) method throws an ObjC exception in case of an error).
197197
* This code is copied below. */
198198
data.withUnsafeBytes{ bytes in
@@ -201,23 +201,20 @@ public struct CLTLogger : LogHandler {
201201
}
202202
var written: Int = 0
203203
repeat {
204-
#if !os(Windows)
204+
/* Note: Windows version takes an UInt32 for the number of bytes to write and returns an Int32.
205+
* It does not matter, fh.fileDescriptor is not accessible on Windows anyways… */
205206
written += write(
206207
fh.fileDescriptor,
207208
bytes.baseAddress!.advanced(by: written),
208209
bytes.count - written
209210
)
210-
#else
211-
written += Int(write(
212-
fh.fileDescriptor,
213-
bytes.baseAddress!.advanced(by: written),
214-
UInt32(bytes.count - written)
215-
))
216-
#endif
217211
} while written < bytes.count && (errno == EINTR || errno == EAGAIN)
218212
}
213+
#else
214+
#error("How can we get here? We can import Darwin, but we are on Windows??")
219215
#endif
220216
} else {
217+
#if !os(Windows)
221218
/* Let’s write “manually” (FileHandle’s write(_:) method throws an ObjC exception in case of an error).
222219
* This is a copy of the code just above. */
223220
data.withUnsafeBytes{ bytes in
@@ -226,21 +223,18 @@ public struct CLTLogger : LogHandler {
226223
}
227224
var written: Int = 0
228225
repeat {
229-
#if !os(Windows)
226+
/* Note: Windows version takes an UInt32 for the number of bytes to write and returns an Int32.
227+
* It does not matter, fh.fileDescriptor is not accessible on Windows anyways… */
230228
written += write(
231229
fh.fileDescriptor,
232230
bytes.baseAddress!.advanced(by: written),
233231
bytes.count - written
234232
)
235-
#else
236-
written += Int(write(
237-
fh.fileDescriptor,
238-
bytes.baseAddress!.advanced(by: written),
239-
UInt32(bytes.count - written)
240-
))
241-
#endif
242233
} while written < bytes.count && (errno == EINTR || errno == EAGAIN)
243234
}
235+
#else
236+
fatalError("Unreachable code reached: In else of #available with only Apple platforms checks, but also on Windows.")
237+
#endif
244238
}
245239
}
246240
}

0 commit comments

Comments
 (0)