From 147ebc053a4026a096e6d74af7b97f52157e4fcc Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Sat, 21 May 2022 11:57:00 -0700 Subject: [PATCH] Unbreak the Windows port --- Sources/System/FileOperations.swift | 8 ++++---- Sources/System/Internals/Syscalls.swift | 18 ++++++++++-------- Tests/SystemTests/FileOperationsTest.swift | 2 ++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Sources/System/FileOperations.swift b/Sources/System/FileOperations.swift index d55b2e8..1193ec9 100644 --- a/Sources/System/FileOperations.swift +++ b/Sources/System/FileOperations.swift @@ -372,9 +372,9 @@ extension FileDescriptor { } } +#if !os(Windows) /*System 1.1.0, @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)*/ extension FileDescriptor { - #if !os(Windows) /// Create a pipe, a unidirectional data channel which can be used for interprocess communication. /// /// - Returns: The pair of file descriptors. @@ -396,12 +396,12 @@ extension FileDescriptor { } }.map { _ in (.init(rawValue: fds.0), .init(rawValue: fds.1)) } } - #endif } +#endif +#if !os(Windows) /*System 1.2.0, @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)*/ extension FileDescriptor { - #if !os(Windows) /// Truncate or extend the file referenced by this file descriptor. /// /// - Parameters: @@ -444,5 +444,5 @@ extension FileDescriptor { system_ftruncate(self.rawValue, _COffT(newSize)) } } - #endif } +#endif diff --git a/Sources/System/Internals/Syscalls.swift b/Sources/System/Internals/Syscalls.swift index 493155b..b22d6a3 100644 --- a/Sources/System/Internals/Syscalls.swift +++ b/Sources/System/Internals/Syscalls.swift @@ -52,14 +52,6 @@ internal func system_close(_ fd: Int32) -> Int32 { return close(fd) } -// truncate -internal func system_ftruncate(_ fd: Int32, _ length: off_t) -> Int32 { -#if ENABLE_MOCKING - if mockingEnabled { return _mock(fd, length) } -#endif - return ftruncate(fd, length) -} - // read internal func system_read( _ fd: Int32, _ buf: UnsafeMutableRawPointer!, _ nbyte: Int @@ -123,6 +115,7 @@ internal func system_dup2(_ fd: Int32, _ fd2: Int32) -> Int32 { #endif return dup2(fd, fd2) } + #if !os(Windows) internal func system_pipe(_ fds: UnsafeMutablePointer) -> CInt { #if ENABLE_MOCKING @@ -131,3 +124,12 @@ internal func system_pipe(_ fds: UnsafeMutablePointer) -> CInt { return pipe(fds) } #endif + +#if !os(Windows) +internal func system_ftruncate(_ fd: Int32, _ length: off_t) -> Int32 { +#if ENABLE_MOCKING + if mockingEnabled { return _mock(fd, length) } +#endif + return ftruncate(fd, length) +} +#endif diff --git a/Tests/SystemTests/FileOperationsTest.swift b/Tests/SystemTests/FileOperationsTest.swift index 2b0a910..a48e87e 100644 --- a/Tests/SystemTests/FileOperationsTest.swift +++ b/Tests/SystemTests/FileOperationsTest.swift @@ -82,9 +82,11 @@ final class FileOperationsTest: XCTestCase { retryOnInterrupt: retryOnInterrupt) }, +#if !os(Windows) MockTestCase(name: "ftruncate", .interruptable, rawFD, 42) { retryOnInterrupt in _ = try fd.resize(to: 42, retryOnInterrupt: retryOnInterrupt) }, +#endif ] for test in syscallTestCases { test.runAllTests() }