ReactOS 0.4.15-dev-5667-ged97270
_system.c File Reference
#include <precomp.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
Include dependency graph for _system.c:

Go to the source code of this file.

Functions

int system (const char *command)
 
int CDECL _wsystem (const wchar_t *cmd)
 

Function Documentation

◆ _wsystem()

int CDECL _wsystem ( const wchar_t cmd)

Definition at line 119 of file _system.c.

120{
121 FIXME("_wsystem stub\n");
122 return -1;
123}
#define FIXME(fmt,...)
Definition: debug.h:111

◆ system()

int system ( const char command)

Definition at line 20 of file _system.c.

21{
22 char *szCmdLine = NULL;
23 char *szComSpec = NULL;
24
25 PROCESS_INFORMATION ProcessInformation;
26 STARTUPINFOA StartupInfo;
27 char *s;
29
30 int nStatus;
31
32 szComSpec = getenv("COMSPEC");
33
34// system should return 0 if command is null and the shell is found
35
36 if (command == NULL) {
37 if (szComSpec == NULL)
38 return 0;
39 else
40 return 1;
41 }
42
43 if (szComSpec == NULL)
44 return -1;
45
46// should return 127 or 0 ( MS ) if the shell is not found
47// _set_errno(ENOENT);
48
49 if (szComSpec == NULL)
50 {
51 szComSpec = "cmd.exe";
52 }
53
54 /* split the path from shell command */
55 s = max(strrchr(szComSpec, '\\'), strrchr(szComSpec, '/'));
56 if (s == NULL)
57 s = szComSpec;
58 else
59 s++;
60
61 szCmdLine = malloc(strlen(s) + 4 + strlen(command) + 1);
62 if (szCmdLine == NULL)
63 {
65 return -1;
66 }
67
68 strcpy(szCmdLine, s);
69 s = strrchr(szCmdLine, '.');
70 if (s)
71 *s = 0;
72 strcat(szCmdLine, " /C ");
73 strcat(szCmdLine, command);
74
75//command file has invalid format ENOEXEC
76
77 memset (&StartupInfo, 0, sizeof(StartupInfo));
78 StartupInfo.cb = sizeof(StartupInfo);
79 StartupInfo.lpReserved= NULL;
80 StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
81 StartupInfo.wShowWindow = SW_SHOWDEFAULT;
82 StartupInfo.lpReserved2 = NULL;
83 StartupInfo.cbReserved2 = 0;
84
85// According to ansi standards the new process should ignore SIGINT and SIGQUIT
86// In order to disable ctr-c the process is created with CREATE_NEW_PROCESS_GROUP,
87// thus SetConsoleCtrlHandler(NULL,TRUE) is made on behalf of the new process.
88
89
90//SIGCHILD should be blocked aswell
91
92 result = CreateProcessA(szComSpec,
93 szCmdLine,
94 NULL,
95 NULL,
96 TRUE,
98 NULL,
99 NULL,
100 &StartupInfo,
101 &ProcessInformation);
102 free(szCmdLine);
103
104 if (result == FALSE)
105 {
107 return -1;
108 }
109
110 CloseHandle(ProcessInformation.hThread);
111
112// system should wait untill the calling process is finished
113 _cwait(&nStatus,(intptr_t)ProcessInformation.hProcess,0);
114 CloseHandle(ProcessInformation.hProcess);
115
116 return nStatus;
117}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define ENOMEM
Definition: acclib.h:84
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
int intptr_t
Definition: crtdefs.h:304
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4742
unsigned int BOOL
Definition: ntddk_ex.h:94
GLdouble s
Definition: gl.h:2039
GLuint64EXT * result
Definition: glext.h:11304
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
errno_t __cdecl _set_errno(_In_ int _Value)
_CRTIMP intptr_t __cdecl _cwait(_Out_opt_ int *_TermStat, _In_ intptr_t _ProcHandle, _In_ int _Action)
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define memset(x, y, z)
Definition: compat.h:39
DWORD dwFlags
Definition: winbase.h:842
DWORD cb
Definition: winbase.h:831
LPSTR lpReserved
Definition: winbase.h:832
WORD wShowWindow
Definition: winbase.h:843
WORD cbReserved2
Definition: winbase.h:844
PBYTE lpReserved2
Definition: winbase.h:845
#define max(a, b)
Definition: svc.c:63
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define STARTF_USESHOWWINDOW
Definition: winbase.h:491
#define CREATE_NEW_PROCESS_GROUP
Definition: winbase.h:185
#define SW_SHOWDEFAULT
Definition: winuser.h:774