@@ -351,35 +351,30 @@ public final class Process {
351
351
pathString: ProcessEnv . path,
352
352
currentWorkingDirectory: cwdOpt
353
353
)
354
+ var searchPaths : [ AbsolutePath ] = [ ]
354
355
#if os(Windows)
355
- var searchPaths = Array < AbsolutePath > ( )
356
356
var buffer = Array < WCHAR > ( repeating: 0 , count: Int ( MAX_PATH + 1 ) )
357
-
358
357
// The 32-bit Windows system directory
359
- GetSystemDirectoryW ( & buffer, . init ( MAX_PATH + 1 ) )
360
- searchPaths. append ( AbsolutePath ( String ( decodingCString: buffer, as: UTF16 . self) ) )
361
-
358
+ if GetSystemDirectoryW ( & buffer, buffer . count ) > 0 {
359
+ searchPaths. append ( AbsolutePath ( String ( decodingCString: buffer, as: UTF16 . self) ) )
360
+ }
362
361
// The 16-bit Windows system directory
363
362
if let systemDrive = ProcessEnv . vars [ " systemdrive " ] ,
364
363
let systemPath = try ? AbsolutePath ( validating: " \( systemDrive) ) \\ System " ) {
365
364
searchPaths. append ( systemPath)
366
365
}
367
-
368
366
// The Windows directory
369
- GetWindowsDirectoryW ( & buffer, . init( MAX_PATH + 1 ) )
370
- searchPaths. append ( AbsolutePath ( String ( decodingCString: buffer, as: UTF16 . self) ) )
371
-
372
- searchPaths. append ( contentsOf: envSearchPaths)
373
- #else
374
- let searchPaths = envSearchPaths
367
+ if GetWindowsDirectoryW ( & buffer, buffer. count) > 0 {
368
+ searchPaths. append ( AbsolutePath ( String ( decodingCString: buffer, as: UTF16 . self) ) )
369
+ }
375
370
#endif
371
+ searchPaths. append ( contentsOf: envSearchPaths)
376
372
// Lookup and cache the executable path.
377
373
let value = lookupExecutablePath (
378
374
filename: program,
379
375
currentWorkingDirectory: cwdOpt,
380
376
searchPaths: searchPaths
381
377
)
382
- Process . validatedExecutablesMap [ program] = value
383
378
return value
384
379
}
385
380
// This should cover the most common cases, i.e. when the cache is most helpful.
0 commit comments