[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
/*
|
2007-03-14 20:24:57 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
2015-09-19 13:50:57 +00:00
|
|
|
* FILE: lib/sdk/crt/process/_system.c
|
2007-03-14 20:24:57 +00:00
|
|
|
* PURPOSE: Excutes a shell command
|
|
|
|
* PROGRAMER: Ariadne
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
* 04/03/99: Created
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <precomp.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <process.h>
|
|
|
|
|
2008-06-06 17:49:24 +00:00
|
|
|
|
2007-03-14 20:24:57 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
int system(const char *command)
|
|
|
|
{
|
|
|
|
char *szCmdLine = NULL;
|
|
|
|
char *szComSpec = NULL;
|
|
|
|
|
|
|
|
PROCESS_INFORMATION ProcessInformation;
|
|
|
|
STARTUPINFOA StartupInfo;
|
|
|
|
char *s;
|
|
|
|
BOOL result;
|
|
|
|
|
|
|
|
int nStatus;
|
|
|
|
|
|
|
|
szComSpec = getenv("COMSPEC");
|
|
|
|
|
|
|
|
// system should return 0 if command is null and the shell is found
|
|
|
|
|
|
|
|
if (command == NULL) {
|
2010-05-29 09:23:23 +00:00
|
|
|
if (szComSpec == NULL)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (szComSpec == NULL)
|
|
|
|
return -1;
|
2007-03-14 20:24:57 +00:00
|
|
|
|
|
|
|
// should return 127 or 0 ( MS ) if the shell is not found
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
// _set_errno(ENOENT);
|
2007-03-14 20:24:57 +00:00
|
|
|
|
|
|
|
if (szComSpec == NULL)
|
|
|
|
{
|
|
|
|
szComSpec = "cmd.exe";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* split the path from shell command */
|
|
|
|
s = max(strrchr(szComSpec, '\\'), strrchr(szComSpec, '/'));
|
|
|
|
if (s == NULL)
|
|
|
|
s = szComSpec;
|
|
|
|
else
|
|
|
|
s++;
|
|
|
|
|
|
|
|
szCmdLine = malloc(strlen(s) + 4 + strlen(command) + 1);
|
|
|
|
if (szCmdLine == NULL)
|
|
|
|
{
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
_set_errno(ENOMEM);
|
2007-03-14 20:24:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(szCmdLine, s);
|
|
|
|
s = strrchr(szCmdLine, '.');
|
|
|
|
if (s)
|
|
|
|
*s = 0;
|
|
|
|
strcat(szCmdLine, " /C ");
|
|
|
|
strcat(szCmdLine, command);
|
|
|
|
|
|
|
|
//command file has invalid format ENOEXEC
|
|
|
|
|
|
|
|
memset (&StartupInfo, 0, sizeof(StartupInfo));
|
|
|
|
StartupInfo.cb = sizeof(StartupInfo);
|
|
|
|
StartupInfo.lpReserved= NULL;
|
|
|
|
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
StartupInfo.wShowWindow = SW_SHOWDEFAULT;
|
|
|
|
StartupInfo.lpReserved2 = NULL;
|
|
|
|
StartupInfo.cbReserved2 = 0;
|
|
|
|
|
|
|
|
// According to ansi standards the new process should ignore SIGINT and SIGQUIT
|
|
|
|
// In order to disable ctr-c the process is created with CREATE_NEW_PROCESS_GROUP,
|
|
|
|
// thus SetConsoleCtrlHandler(NULL,TRUE) is made on behalf of the new process.
|
|
|
|
|
|
|
|
|
|
|
|
//SIGCHILD should be blocked aswell
|
|
|
|
|
|
|
|
result = CreateProcessA(szComSpec,
|
|
|
|
szCmdLine,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
TRUE,
|
|
|
|
CREATE_NEW_PROCESS_GROUP,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&StartupInfo,
|
|
|
|
&ProcessInformation);
|
|
|
|
free(szCmdLine);
|
|
|
|
|
|
|
|
if (result == FALSE)
|
|
|
|
{
|
|
|
|
_dosmaperr(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(ProcessInformation.hThread);
|
|
|
|
|
|
|
|
// system should wait untill the calling process is finished
|
2008-08-27 20:27:32 +00:00
|
|
|
_cwait(&nStatus,(intptr_t)ProcessInformation.hProcess,0);
|
2007-03-14 20:24:57 +00:00
|
|
|
CloseHandle(ProcessInformation.hProcess);
|
|
|
|
|
|
|
|
return nStatus;
|
|
|
|
}
|
2008-05-28 21:08:23 +00:00
|
|
|
|
|
|
|
int CDECL _wsystem(const wchar_t* cmd)
|
|
|
|
{
|
2008-06-06 17:49:24 +00:00
|
|
|
FIXME("_wsystem stub\n");
|
2008-05-28 21:08:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|