Skip to content

Commit fe54c4c

Browse files
committed
Fix problems on Windows
1 parent 1d261e1 commit fe54c4c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Sources/TSCBasic/Process.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,19 +326,19 @@ public final class Process: ObjectIdentifierProtocol {
326326
currentWorkingDirectory: localFileSystem.currentWorkingDirectory
327327
)
328328
#if os(Windows)
329-
var searchPaths = [String]()
330-
let buffer = UnsafeMutablePointer<String>.allocate(capacity: 260)
329+
var searchPaths = Array<AbsolutePath>()
330+
var buffer = Array<WCHAR>(repeating: 0, count: Int(MAX_PATH + 1))
331331

332332
// The 32-bit Windows system directory
333-
GetSystemDirectoryW(buffer, 260)
334-
searchPaths += buffer.pointee
333+
GetSystemDirectoryW(&buffer, .init(MAX_PATH + 1))
334+
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))
335335

336336
// The 16-bit Windows system directory
337-
searchPaths += "\(ProcessEnv.vars["systemdrive"] ?? "C:")\\System"
337+
searchPaths.append(AbsolutePath("\(ProcessEnv.vars["systemdrive"] ?? "C:")\\System"))
338338

339339
// The Windows directory
340-
GetWindowsDirectoryW(buffer, 260)
341-
searchPaths += buffer.pointee
340+
GetWindowsDirectoryW(&buffer, .init(MAX_PATH + 1))
341+
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))
342342

343343
searchPaths.append(contentsOf: envSearchPaths)
344344
#else

Tests/TSCBasicTests/TemporaryFileTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class TemporaryFileTests: XCTestCase {
137137
XCTAssertFalse(localFileSystem.isDirectory(pathTwo))
138138
}
139139

140+
#if !os(Windows) // `fileDescriptor` is currently unavailable in Windows
140141
/// Check that the temporary file doesn't leak file descriptors.
141142
func testLeaks() throws {
142143
// We check this by testing that we get back the same FD after a
@@ -150,4 +151,5 @@ class TemporaryFileTests: XCTestCase {
150151
let endFD = try Int(withTemporaryFile { return $0.fileHandle.fileDescriptor })
151152
XCTAssertEqual(initialFD, endFD)
152153
}
154+
#endif
153155
}

0 commit comments

Comments
 (0)