From 854f39f2ab722b5fd8a5f007d4e77e36cb8b99a8 Mon Sep 17 00:00:00 2001 From: Charles Hu Date: Fri, 9 Aug 2024 11:04:46 -0700 Subject: [PATCH] Fix ProcessInfo.processName for Windows Instead of relying on hard coding PATH_SEPARATOR, use existing .lastPathComponent that already works on Windows --- Sources/FoundationEssentials/Platform.swift | 2 -- .../FoundationEssentials/ProcessInfo/ProcessInfo.swift | 8 +------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/Sources/FoundationEssentials/Platform.swift b/Sources/FoundationEssentials/Platform.swift index bf2e652d3..ffa36466b 100644 --- a/Sources/FoundationEssentials/Platform.swift +++ b/Sources/FoundationEssentials/Platform.swift @@ -49,8 +49,6 @@ package struct Platform { _pageSize } - // FIXME: Windows SEPARATOR - static let PATH_SEPARATOR: Character = "/" static let MAX_HOSTNAME_LENGTH = 1024 static func roundDownToMultipleOfPageSize(_ size: Int) -> Int { diff --git a/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift b/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift index 079ed1e4e..632fe0cc8 100644 --- a/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift +++ b/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift @@ -583,13 +583,7 @@ extension _ProcessInfo { guard let processPath = CommandLine.arguments.first else { return "" } - - if let lastSlash = processPath.lastIndex(of: Platform.PATH_SEPARATOR) { - return String(processPath[ - processPath.index(after: lastSlash) ..< processPath.endIndex]) - } - - return processPath + return processPath.lastPathComponent } #if os(macOS)