mirror of
https://github.com/reactos/reactos.git
synced 2025-04-30 02:58:48 +00:00
Fix for system/_wsystem. Use _set_errno(ENOMEM) for malloc failure. Rename status variable as exit_code.
This commit is contained in:
parent
5a7dbd6064
commit
fdedc549d0
1 changed files with 9 additions and 10 deletions
|
@ -21,11 +21,10 @@ int system(const char *command)
|
||||||
{
|
{
|
||||||
char *szCmdLine = NULL;
|
char *szCmdLine = NULL;
|
||||||
char *szComSpec = NULL;
|
char *szComSpec = NULL;
|
||||||
|
|
||||||
PROCESS_INFORMATION ProcessInformation;
|
PROCESS_INFORMATION ProcessInformation;
|
||||||
STARTUPINFOA StartupInfo;
|
STARTUPINFOA StartupInfo;
|
||||||
BOOL result;
|
BOOL result;
|
||||||
int status;
|
int exit_code;
|
||||||
char cmd_exe[MAX_PATH];
|
char cmd_exe[MAX_PATH];
|
||||||
|
|
||||||
szComSpec = getenv("COMSPEC");
|
szComSpec = getenv("COMSPEC");
|
||||||
|
@ -46,7 +45,7 @@ int system(const char *command)
|
||||||
szCmdLine = malloc(1 + strlen(szComSpec) + 5 + strlen(command) + 1);
|
szCmdLine = malloc(1 + strlen(szComSpec) + 5 + strlen(command) + 1);
|
||||||
if (szCmdLine == NULL)
|
if (szCmdLine == NULL)
|
||||||
{
|
{
|
||||||
_dosmaperr(GetLastError());
|
_set_errno(ENOMEM);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,12 +87,12 @@ int system(const char *command)
|
||||||
CloseHandle(ProcessInformation.hThread);
|
CloseHandle(ProcessInformation.hThread);
|
||||||
|
|
||||||
/* Wait for the process to exit */
|
/* Wait for the process to exit */
|
||||||
_cwait(&status, (intptr_t)ProcessInformation.hProcess, 0);
|
_cwait(&exit_code, (intptr_t)ProcessInformation.hProcess, 0);
|
||||||
|
|
||||||
CloseHandle(ProcessInformation.hProcess);
|
CloseHandle(ProcessInformation.hProcess);
|
||||||
|
|
||||||
_set_errno(0);
|
_set_errno(0);
|
||||||
return status;
|
return exit_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CDECL _wsystem(const wchar_t *cmd)
|
int CDECL _wsystem(const wchar_t *cmd)
|
||||||
|
@ -103,7 +102,7 @@ int CDECL _wsystem(const wchar_t *cmd)
|
||||||
PROCESS_INFORMATION process_info;
|
PROCESS_INFORMATION process_info;
|
||||||
STARTUPINFOW startup_info;
|
STARTUPINFOW startup_info;
|
||||||
BOOL result;
|
BOOL result;
|
||||||
int status;
|
int exit_code;
|
||||||
wchar_t cmd_exe[MAX_PATH];
|
wchar_t cmd_exe[MAX_PATH];
|
||||||
|
|
||||||
comspec = _wgetenv(L"COMSPEC");
|
comspec = _wgetenv(L"COMSPEC");
|
||||||
|
@ -124,7 +123,7 @@ int CDECL _wsystem(const wchar_t *cmd)
|
||||||
cmdline = malloc((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)
|
if (cmdline == NULL)
|
||||||
{
|
{
|
||||||
_dosmaperr(GetLastError());
|
_set_errno(ENOMEM);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,10 +166,10 @@ int CDECL _wsystem(const wchar_t *cmd)
|
||||||
CloseHandle(process_info.hThread);
|
CloseHandle(process_info.hThread);
|
||||||
|
|
||||||
/* Wait for the process to exit */
|
/* Wait for the process to exit */
|
||||||
_cwait(&status, (intptr_t)process_info.hProcess, 0);
|
_cwait(&exit_code, (intptr_t)process_info.hProcess, 0);
|
||||||
|
|
||||||
CloseHandle(process_info.hProcess);
|
CloseHandle(process_info.hProcess);
|
||||||
|
|
||||||
_set_errno(0);
|
_set_errno(0);
|
||||||
return status;
|
return exit_code;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue