ReactOS 0.4.16-dev-927-g467dec4
spawnl.cpp
Go to the documentation of this file.
1//
2// spawnl.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines the -l and -le 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::tspawnve(mode, file_name, captured_arguments, environment);
51}
52
53
54
56 char const* const file_name,
57 char const* const arguments,
58 ...
59 )
60{
61 va_list varargs;
62 va_start(varargs, arguments);
63 return common_spawnl(false, _P_OVERLAY, file_name, arguments, varargs);
64}
65
67 char const* const file_name,
68 char const* const arguments,
69 ...)
70{
71 va_list varargs;
72 va_start(varargs, arguments);
73 return common_spawnl(true, _P_OVERLAY, file_name, arguments, varargs);
74}
75
77 int const mode,
78 char const* const file_name,
79 char const* const arguments,
80 ...
81 )
82{
83 va_list varargs;
84 va_start(varargs, arguments);
85 return common_spawnl(false, mode, file_name, arguments, varargs);
86}
87
89 int const mode,
90 char const* const file_name,
91 char const* const arguments,
92 ...)
93{
94 va_list varargs;
95 va_start(varargs, arguments);
96 return common_spawnl(true, mode, file_name, arguments, varargs);
97}
98
99
100
102 wchar_t const* const file_name,
103 wchar_t const* const arguments,
104 ...
105 )
106{
107 va_list varargs;
108 va_start(varargs, arguments);
109 return common_spawnl(false, _P_OVERLAY, file_name, arguments, varargs);
110}
111
113 wchar_t const* const file_name,
114 wchar_t const* const arguments,
115 ...)
116{
117 va_list varargs;
118 va_start(varargs, arguments);
119 return common_spawnl(true, _P_OVERLAY, file_name, arguments, varargs);
120}
121
123 int const mode,
124 wchar_t const* const file_name,
125 wchar_t const* const arguments,
126 ...
127 )
128{
129 va_list varargs;
130 va_start(varargs, arguments);
131 return common_spawnl(false, mode, file_name, arguments, varargs);
132}
133
135 int const mode,
136 wchar_t const* const file_name,
137 wchar_t const* const arguments,
138 ...)
139{
140 va_list varargs;
141 va_start(varargs, arguments);
142 return common_spawnl(true, mode, file_name, arguments, varargs);
143}
#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
static intptr_t __cdecl common_spawnl(bool const pass_environment, int const mode, Character const *const file_name, Character const *const arguments, va_list varargs)
Definition: spawnl.cpp:19
intptr_t __cdecl _execl(char const *const file_name, char const *const arguments,...)
Definition: spawnl.cpp:55
intptr_t __cdecl _execle(char const *const file_name, char const *const arguments,...)
Definition: spawnl.cpp:66
intptr_t __cdecl _wspawnle(int const mode, wchar_t const *const file_name, wchar_t const *const arguments,...)
Definition: spawnl.cpp:134
intptr_t __cdecl _wexecl(wchar_t const *const file_name, wchar_t const *const arguments,...)
Definition: spawnl.cpp:101
intptr_t __cdecl _spawnle(int const mode, char const *const file_name, char const *const arguments,...)
Definition: spawnl.cpp:88
intptr_t __cdecl _spawnl(int const mode, char const *const file_name, char const *const arguments,...)
Definition: spawnl.cpp:76
intptr_t __cdecl _wexecle(wchar_t const *const file_name, wchar_t const *const arguments,...)
Definition: spawnl.cpp:112
intptr_t __cdecl _wspawnl(int const mode, wchar_t const *const file_name, wchar_t const *const arguments,...)
Definition: spawnl.cpp:122
int intptr_t
Definition: vcruntime.h:134