From 6e50926c570b714aad22850b53d7bafe08b80a15 Mon Sep 17 00:00:00 2001 From: AZero13 Date: Wed, 10 Dec 2025 13:17:54 -0500 Subject: [PATCH] GetUserNameExW returns 0 on error, non-zero on success I know Microsoft is not consistent on this, but yes. --- Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift | 2 +- Tests/FoundationEssentialsTests/ProcessInfoTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift b/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift index acb94408e..51509a557 100644 --- a/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift +++ b/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift @@ -229,7 +229,7 @@ final class _ProcessInfo: Sendable { _ = GetUserNameExW(NameDisplay, nil, &ulLength) return withUnsafeTemporaryAllocation(of: WCHAR.self, capacity: Int(ulLength)) { wszBuffer in - guard GetUserNameExW(NameDisplay, wszBuffer.baseAddress!, &ulLength) == 0 else { + guard GetUserNameExW(NameDisplay, wszBuffer.baseAddress!, &ulLength) != 0 else { return "" } return String(decoding: wszBuffer.prefix(Int(ulLength)), as: UTF16.self) diff --git a/Tests/FoundationEssentialsTests/ProcessInfoTests.swift b/Tests/FoundationEssentialsTests/ProcessInfoTests.swift index 2dfe31ce0..2e98f308d 100644 --- a/Tests/FoundationEssentialsTests/ProcessInfoTests.swift +++ b/Tests/FoundationEssentialsTests/ProcessInfoTests.swift @@ -147,7 +147,7 @@ private struct ProcessInfoTests { "ProcessInfo thinks we are on System 70") } -#if os(macOS) +#if canImport(Darwin) || os(Windows) @Test func userName() { #expect(!ProcessInfo.processInfo.userName.isEmpty) }