Skip to content

Commit 8b27878

Browse files
committed
Fix compilation on very old Darwin platforms
1 parent edddb05 commit 8b27878

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Tests/JSONLoggerTests/Helpers/FileHandleHelper.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,23 @@ extension FileHandle {
2626

2727
func jl_readToEnd() throws -> Data? {
2828
if #available(macOS 10.15, tvOS 13.0, iOS 13.0, watchOS 6.0, *) {
29+
#if swift(>=5.2) || !canImport(Darwin)
2930
return try readToEnd()
31+
#else
32+
let buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: 512, alignment: MemoryLayout<UInt8>.alignment)
33+
defer {buffer.deallocate()}
34+
35+
var nread = 0
36+
var ret = Data()
37+
repeat {
38+
nread = system_read(fileDescriptor, buffer.baseAddress, buffer.count)
39+
ret += buffer
40+
} while nread > 0
41+
guard nread >= 0 else {
42+
throw Errno()
43+
}
44+
return ret
45+
#endif
3046
} else {
3147
let buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: 512, alignment: MemoryLayout<UInt8>.alignment)
3248
defer {buffer.deallocate()}

0 commit comments

Comments
 (0)