IO (Windows): prefers native functions

This commit is contained in:
李通洲
2026-03-11 23:28:41 +08:00
parent c9b7c65ba5
commit d2de3a01bb
2 changed files with 20 additions and 6 deletions
+11 -6
View File
@@ -2,6 +2,7 @@
#include "common/io.h"
#include "common/stringUtils.h"
#include "common/windows/nt.h"
#include "common/windows/unicode.h"
#include <windows.h>
@@ -314,13 +315,17 @@ bool ffPathExpandEnv(const char* in, FFstrbuf* out)
}
}
DWORD length = ExpandEnvironmentStringsA(in, NULL, 0);
if (length <= 1) return false;
wchar_t pathInW[MAX_PATH], pathOutW[MAX_PATH];
ULONG len = (ULONG) strlen(in);
if (!NT_SUCCESS(RtlUTF8ToUnicodeN(pathInW, (ULONG) sizeof(pathInW), &len, in, len)))
return false;
len /= sizeof(wchar_t); // convert from bytes to characters
ffStrbufClear(out);
ffStrbufEnsureFree(out, (uint32_t)length);
ExpandEnvironmentStringsA(in, out->chars, length);
out->length = (uint32_t)length - 1;
size_t outLen; // in characters, including null terminator
if (!NT_SUCCESS(RtlExpandEnvironmentStrings(NULL, pathInW, len, pathOutW, ARRAY_SIZE(pathOutW), &outLen)))
return false;
ffStrbufSetNWS(out, (uint32_t) outLen - 1, pathOutW);
return true;
}
+9
View File
@@ -996,3 +996,12 @@ static inline RTL_USER_PROCESS_PARAMETERS_FULL* ffGetProcessParams()
{
return (RTL_USER_PROCESS_PARAMETERS_FULL*) NtCurrentTeb()->ProcessEnvironmentBlock->ProcessParameters;
}
NTSYSAPI NTSTATUS NTAPI RtlExpandEnvironmentStrings(
_In_opt_ PVOID Environment,
_In_reads_(SourceLength) PCWSTR Source,
_In_ SIZE_T SourceLength,
_Out_writes_(DestinationLength) PWSTR Destination,
_In_ SIZE_T DestinationLength,
_Out_opt_ PSIZE_T ReturnLength
);