Skip to content

Commit 8edfda9

Browse files
committed
Processing (Windows): prefers *W version APIs
1 parent cc3595c commit 8edfda9

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/common/impl/processing_windows.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "fastfetch.h"
2+
#include "common/mallocHelper.h"
23
#include "common/processing.h"
34
#include "common/io.h"
45
#include "common/windows/unicode.h"
@@ -85,7 +86,7 @@ const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFProcessHandle*
8586
return "CreateFileW(L\"\\\\.\\pipe\\FASTFETCH-$(PID)\") failed";
8687

8788
PROCESS_INFORMATION piProcInfo = {};
88-
STARTUPINFOA siStartInfo = {
89+
STARTUPINFOW siStartInfo = {
8990
.cb = sizeof(siStartInfo),
9091
.dwFlags = STARTF_USESTDHANDLES,
9192
};
@@ -100,12 +101,19 @@ const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFProcessHandle*
100101
siStartInfo.hStdError = ffGetNullFD();
101102
}
102103

103-
FF_STRBUF_AUTO_DESTROY cmdline = ffStrbufCreate();
104-
argvToCmdline(argv, &cmdline);
104+
FF_AUTO_FREE wchar_t* cmdline = NULL;
105+
{
106+
FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate();
107+
argvToCmdline(argv, &buf);
108+
uint32_t cmdlineBytes = (buf.length + 1) * sizeof(wchar_t);
109+
cmdline = malloc(cmdlineBytes);
110+
if (!NT_SUCCESS(RtlUTF8ToUnicodeN(cmdline, cmdlineBytes, NULL, buf.chars, buf.length + 1)))
111+
return "RtlUTF8ToUnicodeN() failed";
112+
}
105113

106-
BOOL success = CreateProcessA(
114+
BOOL success = CreateProcessW(
107115
NULL, // application name
108-
cmdline.chars, // command line
116+
cmdline, // command line
109117
NULL, // process security attributes
110118
NULL, // primary thread security attributes
111119
TRUE, // handles are inherited
@@ -121,7 +129,7 @@ const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFProcessHandle*
121129
{
122130
if (GetLastError() == ERROR_FILE_NOT_FOUND)
123131
return "command not found";
124-
return "CreateProcessA() failed";
132+
return "CreateProcessW() failed";
125133
}
126134

127135
NtClose(piProcInfo.hThread); // we don't need the thread handle

0 commit comments

Comments
 (0)