Reactos
at master 143 lines 3.7 kB view raw
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> 11#include <corecrt_internal_traits.h> 12#include <stddef.h> 13#include <process.h> 14#include <stdarg.h> 15 16 17 18template <typename Character> 19static intptr_t __cdecl common_spawnl( 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 55extern "C" intptr_t __cdecl _execl( 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 66extern "C" intptr_t __cdecl _execle( 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 76extern "C" intptr_t __cdecl _spawnl( 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 88extern "C" intptr_t __cdecl _spawnle( 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 101extern "C" intptr_t __cdecl _wexecl( 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 112extern "C" intptr_t __cdecl _wexecle( 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 122extern "C" intptr_t __cdecl _wspawnl( 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 134extern "C" intptr_t __cdecl _wspawnle( 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}