https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5a7dbd6064e74e1ed2b88…
commit 5a7dbd6064e74e1ed2b886dcd973d444d2a8dc4d
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sun Mar 5 23:20:12 2023 +0900
Commit: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
CommitDate: Sun Mar 5 23:20:12 2023 +0900
[MSVCRT] Follow-up of #5032 (f172503)
Use _cwait() instead of WaitForSingleObject and GetExitCodeProcess.
Use malloc/free instead of LocalAlloc/LocalFree.
---
sdk/lib/crt/process/_system.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/sdk/lib/crt/process/_system.c b/sdk/lib/crt/process/_system.c
index 6ce5b117808..2b2696e6d45 100644
--- a/sdk/lib/crt/process/_system.c
+++ b/sdk/lib/crt/process/_system.c
@@ -14,7 +14,6 @@
#include <string.h>
#include <process.h>
-
/*
* @implemented
*/
@@ -26,7 +25,7 @@ int system(const char *command)
PROCESS_INFORMATION ProcessInformation;
STARTUPINFOA StartupInfo;
BOOL result;
- DWORD exit_code;
+ int status;
char cmd_exe[MAX_PATH];
szComSpec = getenv("COMSPEC");
@@ -44,7 +43,7 @@ int system(const char *command)
szComSpec = cmd_exe;
}
- szCmdLine = LocalAlloc(LPTR, 1 + strlen(szComSpec) + 5 + strlen(command) + 1);
+ szCmdLine = malloc(1 + strlen(szComSpec) + 5 + strlen(command) + 1);
if (szCmdLine == NULL)
{
_dosmaperr(GetLastError());
@@ -78,7 +77,7 @@ int system(const char *command)
NULL,
&StartupInfo,
&ProcessInformation);
- LocalFree(szCmdLine);
+ free(szCmdLine);
if (result == FALSE)
{
@@ -89,23 +88,22 @@ int system(const char *command)
CloseHandle(ProcessInformation.hThread);
/* Wait for the process to exit */
- WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
- GetExitCodeProcess(ProcessInformation.hProcess, &exit_code);
+ _cwait(&status, (intptr_t)ProcessInformation.hProcess, 0);
CloseHandle(ProcessInformation.hProcess);
_set_errno(0);
- return (int)exit_code;
+ return status;
}
-int CDECL _wsystem(const wchar_t* cmd)
+int CDECL _wsystem(const wchar_t *cmd)
{
wchar_t *cmdline = NULL;
wchar_t *comspec = NULL;
PROCESS_INFORMATION process_info;
STARTUPINFOW startup_info;
BOOL result;
- DWORD exit_code;
+ int status;
wchar_t cmd_exe[MAX_PATH];
comspec = _wgetenv(L"COMSPEC");
@@ -123,7 +121,7 @@ int CDECL _wsystem(const wchar_t* cmd)
comspec = cmd_exe;
}
- cmdline = LocalAlloc(LPTR, (1 + wcslen(comspec) + 5 + wcslen(cmd) + 1) *
sizeof(wchar_t));
+ cmdline = malloc((1 + wcslen(comspec) + 5 + wcslen(cmd) + 1) * sizeof(wchar_t));
if (cmdline == NULL)
{
_dosmaperr(GetLastError());
@@ -158,7 +156,7 @@ int CDECL _wsystem(const wchar_t* cmd)
NULL,
&startup_info,
&process_info);
- LocalFree(cmdline);
+ free(cmdline);
if (!result)
{
@@ -169,11 +167,10 @@ int CDECL _wsystem(const wchar_t* cmd)
CloseHandle(process_info.hThread);
/* Wait for the process to exit */
- WaitForSingleObject(process_info.hProcess, INFINITE);
- GetExitCodeProcess(process_info.hProcess, &exit_code);
+ _cwait(&status, (intptr_t)process_info.hProcess, 0);
CloseHandle(process_info.hProcess);
_set_errno(0);
- return (int)exit_code;
+ return status;
}