Skip to content

Commit b238331

Browse files
committed
Fix compilation of the test target on Windows
1 parent 59f635e commit b238331

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

Tests/JSONLoggerTests/Helpers/FileHandleHelper.swift

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,55 @@ extension FileHandle {
1919
if #available(macOS 10.15, *) {
2020
try close()
2121
} else {
22+
#if !os(Windows)
2223
/* closeFile exists but I’m not sure it never throws an ObjC exception, so I call the C function. */
2324
let ret = system_close(fileDescriptor)
2425
guard ret == 0 else {
2526
throw Errno()
2627
}
28+
#else
29+
fatalError("Unreachable code reached: In else of #available with only Apple platforms checks, but also on Windows.")
30+
#endif
2731
}
2832
}
2933

3034
func jl_readToEnd() throws -> Data? {
3135
if #available(macOS 10.15, tvOS 13.0, iOS 13.0, watchOS 6.0, *) {
3236
#if swift(>=5.2) || !canImport(Darwin)
3337
return try readToEnd()
34-
#else
38+
#elseif !os(Windows)
3539
let buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: 512, alignment: MemoryLayout<UInt8>.alignment)
3640
defer {buffer.deallocate()}
3741

38-
#if !os(Windows)
3942
var nread = 0
40-
let bufferCount = buffer.count
41-
#else
42-
var nread = Int32(0)
43-
let bufferCount = UInt32(buffer.count)
44-
#endif
4543
var ret = Data()
46-
while ({ nread = system_read(fileDescriptor, buffer.baseAddress, bufferCount); return nread }()) > 0 {
44+
while ({ nread = system_read(fileDescriptor, buffer.baseAddress, buffer.count); return nread }()) > 0 {
4745
ret += buffer[0..<Int(nread)]
4846
}
4947
guard nread >= 0 else {
5048
throw Errno()
5149
}
5250
return ret
51+
#else
52+
#error("How can we get here? We can import Darwin, but we are on Windows??")
5353
#endif
5454
} else {
55+
#if !os(Windows)
5556
let buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: 512, alignment: MemoryLayout<UInt8>.alignment)
5657
defer {buffer.deallocate()}
5758

58-
#if !os(Windows)
5959
var nread = 0
60-
let bufferCount = buffer.count
61-
#else
62-
var nread = Int32(0)
63-
let bufferCount = UInt32(buffer.count)
64-
#endif
6560
var ret = Data()
66-
while ({ nread = system_read(fileDescriptor, buffer.baseAddress, bufferCount); return nread }()) > 0 {
61+
while ({ nread = system_read(fileDescriptor, buffer.baseAddress, buffer.count); return nread }()) > 0 {
6762
ret += buffer[0..<Int(nread)]
6863
}
6964
guard nread >= 0 else {
7065
throw Errno()
7166
}
7267
return ret
68+
#else
69+
fatalError("Unreachable code reached: In else of #available with only Apple platforms checks, but also on Windows.")
70+
#endif
7371
}
7472
}
7573

0 commit comments

Comments
 (0)