ReactOS 0.4.16-dev-2122-g1628f5e
system.cpp File Reference
#include <process.h>
#include <io.h>
#include <stdlib.h>
#include <errno.h>
Include dependency graph for system.cpp:

Go to the source code of this file.

Functions

int _cdecl _access_s (const char *filename, int mode)
 
int _cdecl _waccess_s (const wchar_t *filename, int mode)
 
int _cdecl _taccess_s (const char *filename, int mode)
 
int _cdecl _taccess_s (const wchar_t *filename, int mode)
 
char *__cdecl _tgetenv (_In_z_ char const *_VarName)
 
wchar_t *__cdecl _tgetenv (_In_z_ wchar_t const *_VarName)
 
intptr_t __cdecl _tspawnve (int flags, const char *name, const char *const *argv, const char *const *envv)
 
intptr_t __cdecl _tspawnve (int flags, const wchar_t *name, const wchar_t *const *argv, const wchar_t *const *envv)
 
intptr_t __cdecl _tspawnvpe (int flags, const char *name, const char *const *argv, const char *const *envv)
 
intptr_t __cdecl _tspawnvpe (int flags, const wchar_t *name, const wchar_t *const *argv, const wchar_t *const *envv)
 
template<typename Character >
static int __cdecl common_system (Character const *const command) throw ()
 
int __cdecl system (char const *const command)
 
int __cdecl _wsystem (wchar_t const *const command)
 

Function Documentation

◆ _access_s()

int _cdecl _access_s ( const char filename,
int  mode 
)

Definition at line 1004 of file file.c.

1005{
1006 if (!MSVCRT_CHECK_PMT(filename != NULL)) return *_errno();
1007 if (!MSVCRT_CHECK_PMT((mode & ~(MSVCRT_R_OK | MSVCRT_W_OK)) == 0)) return *_errno();
1008
1009 if (_access(filename, mode) == -1)
1010 return *_errno();
1011 return 0;
1012}
#define NULL
Definition: types.h:112
int *CDECL _errno(void)
Definition: errno.c:215
#define MSVCRT_W_OK
Definition: file.c:76
#define MSVCRT_R_OK
Definition: file.c:77
int CDECL _access(const char *filename, int mode)
Definition: file.c:990
#define MSVCRT_CHECK_PMT(x)
Definition: msvcrt.h:378
GLenum mode
Definition: glext.h:6217
const char * filename
Definition: ioapi.h:137

Referenced by _access(), and _taccess_s().

◆ _taccess_s() [1/2]

int _cdecl _taccess_s ( const char filename,
int  mode 
)

Definition at line 17 of file system.cpp.

18{
19 return _access_s(filename, mode);
20}
int _cdecl _access_s(const char *filename, int mode)
Definition: file.c:1004

◆ _taccess_s() [2/2]

int _cdecl _taccess_s ( const wchar_t filename,
int  mode 
)

Definition at line 22 of file system.cpp.

23{
24 return _waccess_s(filename, mode);
25}
int _cdecl _waccess_s(const wchar_t *filename, int mode)
Definition: file.c:1039

◆ _tgetenv() [1/2]

char *__cdecl _tgetenv ( _In_z_ char const _VarName)

Definition at line 27 of file system.cpp.

28{
29 return getenv(_VarName);
30}
char *CDECL getenv(const char *name)
Definition: environ.c:227

◆ _tgetenv() [2/2]

wchar_t *__cdecl _tgetenv ( _In_z_ wchar_t const _VarName)

Definition at line 32 of file system.cpp.

33{
34 return _wgetenv(_VarName);
35}
wchar_t *CDECL _wgetenv(const wchar_t *name)
Definition: environ.c:254

◆ _tspawnve() [1/2]

intptr_t __cdecl _tspawnve ( int  flags,
const char name,
const char *const argv,
const char *const envv 
)

Definition at line 37 of file system.cpp.

39{
40 return _spawnve(flags, name, argv, envv);
41}
_ACRTIMP intptr_t __cdecl _spawnve(int, const char *, const char *const *, const char *const *)
Definition: process.c:900
GLbitfield flags
Definition: glext.h:7161
#define argv
Definition: mplay32.c:18
Definition: name.c:39

◆ _tspawnve() [2/2]

intptr_t __cdecl _tspawnve ( int  flags,
const wchar_t name,
const wchar_t *const argv,
const wchar_t *const envv 
)

Definition at line 43 of file system.cpp.

45{
46 return _wspawnve(flags, name, argv, envv);
47}
_ACRTIMP intptr_t __cdecl _wspawnve(int, const wchar_t *, const wchar_t *const *, const wchar_t *const *)
Definition: process.c:924

◆ _tspawnvpe() [1/2]

intptr_t __cdecl _tspawnvpe ( int  flags,
const char name,
const char *const argv,
const char *const envv 
)

Definition at line 49 of file system.cpp.

51{
52 return _spawnvpe(flags, name, argv, envv);
53}
_ACRTIMP intptr_t __cdecl _spawnvpe(int, const char *, const char *const *, const char *const *)
Definition: process.c:967

◆ _tspawnvpe() [2/2]

intptr_t __cdecl _tspawnvpe ( int  flags,
const wchar_t name,
const wchar_t *const argv,
const wchar_t *const envv 
)

Definition at line 55 of file system.cpp.

57{
58 return _wspawnvpe(flags, name, argv, envv);
59}
_ACRTIMP intptr_t __cdecl _wspawnvpe(int, const wchar_t *, const wchar_t *const *, const wchar_t *const *)
Definition: process.c:991

◆ _waccess_s()

int _cdecl _waccess_s ( const wchar_t filename,
int  mode 
)

Definition at line 1039 of file file.c.

1040{
1041 if (!MSVCRT_CHECK_PMT(filename != NULL)) return *_errno();
1042 if (!MSVCRT_CHECK_PMT((mode & ~(MSVCRT_R_OK | MSVCRT_W_OK)) == 0)) return *_errno();
1043
1044 if (_waccess(filename, mode) == -1)
1045 return *_errno();
1046 return 0;
1047}
int CDECL _waccess(const wchar_t *filename, int mode)
Definition: file.c:1017

Referenced by _access_s(), _taccess_s(), and _waccess().

◆ _wsystem()

int __cdecl _wsystem ( wchar_t const *const  command)

Definition at line 120 of file system.cpp.

121{
122 return common_system(command);
123}
static int __cdecl common_system(Character const *const command)
Definition: system.cpp:62

◆ common_system()

template<typename Character >
static int __cdecl common_system ( Character const *const  command)
throw (
)
static

Definition at line 62 of file system.cpp.

63{
64 static Character const comspec_name[] = { 'C', 'O', 'M', 'S', 'P', 'E', 'C', '\0' }; // "COMSPEC"
65 static Character const cmd_exe[] = { 'c', 'm', 'd', '.', 'e', 'x', 'e', '\0' }; // "cmd.exe"
66 static Character const slash_c[] = { '/', 'c', '\0' }; // "/c"
67
68 Character const * comspec_value = _tgetenv(comspec_name);
69
70 // If the command is null, return TRUE only if %COMSPEC% is set and the file
71 // to which it points exists.
72 if (!command)
73 {
74 if (!comspec_value)
75 return 0;
76
77 return _taccess_s(comspec_value, 0) == 0;
78 }
79
80 Character const* arguments[4] =
81 {
82 comspec_value,
83 slash_c,
84 command,
85 nullptr
86 };
87
88 if (comspec_value)
89 {
90 errno_t const saved_errno = errno;
91 errno = 0;
92
93 int const result = static_cast<int>(_tspawnve(_P_WAIT, arguments[0], arguments, nullptr));
94 if (result != -1)
95 {
96 errno = saved_errno;
97 return result;
98 }
99
100 if (errno != ENOENT && errno != EACCES)
101 {
102 return result;
103 }
104
105 // If the error wasn't one of those two errors, try again with cmd.exe...
106 errno = saved_errno;
107 }
108
109 arguments[0] = cmd_exe;
110 return static_cast<int>(_tspawnvpe(_P_WAIT, arguments[0], arguments, nullptr));
111
112 return 0;
113}
int errno_t
Definition: corecrt.h:249
#define ENOENT
Definition: errno.h:25
#define errno
Definition: errno.h:120
#define EACCES
Definition: errno.h:36
#define _P_WAIT
Definition: process.h:15
GLuint64EXT * result
Definition: glext.h:11304
#define _tspawnvpe
Definition: tchar.h:649
#define _tgetenv
Definition: tchar.h:680
#define _tspawnve
Definition: tchar.h:647
#define _taccess_s
Definition: tchar.h:1185

Referenced by _wsystem(), and system().

◆ system()

int __cdecl system ( char const *const  command)

Definition at line 115 of file system.cpp.

116{
117 return common_system(command);
118}