Skip to content

Commit a7c43e0

Browse files
committed
Merge branch 'fix/frizlab/compilation_on_windows' into develop
2 parents c4c585d + 63a83c9 commit a7c43e0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Sources/CLTLogger.swift

Lines changed: 11 additions & 1 deletion
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,15 +201,20 @@ public struct CLTLogger : LogHandler {
201201
}
202202
var written: Int = 0
203203
repeat {
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… */
204206
written += write(
205207
fh.fileDescriptor,
206208
bytes.baseAddress!.advanced(by: written),
207209
bytes.count - written
208210
)
209211
} while written < bytes.count && (errno == EINTR || errno == EAGAIN)
210212
}
213+
#else
214+
#error("How can we get here? We can import Darwin, but we are on Windows??")
211215
#endif
212216
} else {
217+
#if !os(Windows)
213218
/* Let’s write “manually” (FileHandle’s write(_:) method throws an ObjC exception in case of an error).
214219
* This is a copy of the code just above. */
215220
data.withUnsafeBytes{ bytes in
@@ -218,13 +223,18 @@ public struct CLTLogger : LogHandler {
218223
}
219224
var written: Int = 0
220225
repeat {
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… */
221228
written += write(
222229
fh.fileDescriptor,
223230
bytes.baseAddress!.advanced(by: written),
224231
bytes.count - written
225232
)
226233
} while written < bytes.count && (errno == EINTR || errno == EAGAIN)
227234
}
235+
#else
236+
fatalError("Unreachable code reached: In else of #available with only Apple platforms checks, but also on Windows.")
237+
#endif
228238
}
229239
}
230240
}

0 commit comments

Comments
 (0)