ReactOS 0.4.16-dev-959-g2ec3a19
spawnlp.cpp
Go to the documentation of this file.
1//
2// spawnlp.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines the -lp and -lpe flavors of the _exec() and _spawn() functions. See
7// the comments in spawnv.cpp for details of the various flavors of these
8// functions.
9//
10#include <corecrt_internal.h>
12#include <stddef.h>
13#include <process.h>
14#include <stdarg.h>
15
16
17
18template <typename Character>
20 bool const pass_environment,
21 int const mode,
22 Character const* const file_name,
23 Character const* const arguments,
24 va_list varargs
25 ) throw()
26{
27 typedef __crt_char_traits<Character> traits;
28
29 _VALIDATE_RETURN(file_name != nullptr, EINVAL, -1);
30 _VALIDATE_RETURN(file_name[0] != '\0', EINVAL, -1);
31 _VALIDATE_RETURN(arguments != nullptr, EINVAL, -1);
32 _VALIDATE_RETURN(arguments[0] != '\0', EINVAL, -1);
33
34 Character* arguments_buffer[64];
35 Character** const captured_arguments = traits::capture_argv(
36 &varargs,
37 arguments,
38 &arguments_buffer[0],
39 64);
40
41 _VALIDATE_RETURN_NOEXC(captured_arguments != nullptr, ENOMEM, -1);
42
43 __crt_unique_heap_ptr<Character*> const captured_arguments_cleanup(
44 captured_arguments == arguments_buffer ? nullptr : captured_arguments);
45
46 Character const* const* const environment = pass_environment
47 ? va_arg(varargs, Character const* const*)
48 : nullptr;
49
50 return traits::tspawnvpe(mode, file_name, captured_arguments, environment);
51}
52
53
54
55extern "C" intptr_t _execlp(
56 char const* const file_name,
57 char const* const arguments,
58 ...)
59{
60 va_list varargs;
61 va_start(varargs, arguments);
62 return common_spawnlp(false, _P_OVERLAY, file_name, arguments, varargs);
63}
64
65extern "C" intptr_t _execlpe(
66 char const* const file_name,
67 char const* const arguments,
68 ...)
69{
70 va_list varargs;
71 va_start(varargs, arguments);
72 return common_spawnlp(true, _P_OVERLAY, file_name, arguments, varargs);
73}
74
75extern "C" intptr_t _spawnlp(
76 int const mode,
77 char const* const file_name,
78 char const* const arguments,
79 ...)
80{
81 va_list varargs;
82 va_start(varargs, arguments);
83 return common_spawnlp(false, mode, file_name, arguments, varargs);
84}
85
87 int const mode,
88 char const* const file_name,
89 char const* const arguments,
90 ...)
91{
92 va_list varargs;
93 va_start(varargs, arguments);
94 return common_spawnlp(true, mode, file_name, arguments, varargs);
95}
96
97
98
99extern "C" intptr_t _wexeclp(
100 wchar_t const* const file_name,
101 wchar_t const* const arguments,
102 ...)
103{
104 va_list varargs;
105 va_start(varargs, arguments);
106 return common_spawnlp(false, _P_OVERLAY, file_name, arguments, varargs);
107}
108
110 wchar_t const* const file_name,
111 wchar_t const* const arguments,
112 ...)
113{
114 va_list varargs;
115 va_start(varargs, arguments);
116 return common_spawnlp(true, _P_OVERLAY, file_name, arguments, varargs);
117}
118
120 int const mode,
121 wchar_t const* const file_name,
122 wchar_t const* const arguments,
123 ...)
124{
125 va_list varargs;
126 va_start(varargs, arguments);
127 return common_spawnlp(false, mode, file_name, arguments, varargs);
128}
129
131 int const mode,
132 wchar_t const* const file_name,
133 wchar_t const* const arguments,
134 ...)
135{
136 va_list varargs;
137 va_start(varargs, arguments);
138 return common_spawnlp(true, mode, file_name, arguments, varargs);
139}
140
#define EINVAL
Definition: acclib.h:90
#define ENOMEM
Definition: acclib.h:84
#define __cdecl
Definition: accygwin.h:79
char * va_list
Definition: acmsvcex.h:78
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define va_arg(ap, T)
Definition: acmsvcex.h:89
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
GLenum mode
Definition: glext.h:6217
#define _VALIDATE_RETURN_NOEXC(expr, errorcode, retexpr)
static LPCWSTR file_name
Definition: protocol.c:147
#define _P_OVERLAY
Definition: port.h:372
intptr_t _wspawnlp(int const mode, wchar_t const *const file_name, wchar_t const *const arguments,...)
Definition: spawnlp.cpp:119
intptr_t _wexeclpe(wchar_t const *const file_name, wchar_t const *const arguments,...)
Definition: spawnlp.cpp:109
intptr_t _spawnlp(int const mode, char const *const file_name, char const *const arguments,...)
Definition: spawnlp.cpp:75
intptr_t _wspawnlpe(int const mode, wchar_t const *const file_name, wchar_t const *const arguments,...)
Definition: spawnlp.cpp:130
intptr_t _wexeclp(wchar_t const *const file_name, wchar_t const *const arguments,...)
Definition: spawnlp.cpp:99
static intptr_t __cdecl common_spawnlp(bool const pass_environment, int const mode, Character const *const file_name, Character const *const arguments, va_list varargs)
Definition: spawnlp.cpp:19
intptr_t _execlpe(char const *const file_name, char const *const arguments,...)
Definition: spawnlp.cpp:65
intptr_t _spawnlpe(int const mode, char const *const file_name, char const *const arguments,...)
Definition: spawnlp.cpp:86
intptr_t _execlp(char const *const file_name, char const *const arguments,...)
Definition: spawnlp.cpp:55
int intptr_t
Definition: vcruntime.h:134