ReactOS  0.4.13-dev-563-g0561610
_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:110

◆ 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;
28  BOOL result;
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 }
errno_t __cdecl _set_errno(_In_ int _Value)
#define SW_SHOWDEFAULT
Definition: winuser.h:774
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define free
Definition: debug_ros.c:5
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD dwFlags
Definition: winbase.h:807
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define CREATE_NEW_PROCESS_GROUP
Definition: winbase.h:185
Definition: arc.h:48
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
PBYTE lpReserved2
Definition: winbase.h:810
_CRTIMP intptr_t __cdecl _cwait(_Out_opt_ int *_TermStat, _In_ intptr_t _ProcHandle, _In_ int _Action)
LPSTR lpReserved
Definition: winbase.h:797
#define STARTF_USESHOWWINDOW
Definition: winbase.h:472
DWORD cb
Definition: winbase.h:796
int intptr_t
Definition: crtdefs.h:283
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:4772
GLdouble s
Definition: gl.h:2039
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
WORD cbReserved2
Definition: winbase.h:809
WORD wShowWindow
Definition: winbase.h:808
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define malloc
Definition: debug_ros.c:4
GLuint64EXT * result
Definition: glext.h:11304
#define memset(x, y, z)
Definition: compat.h:39