return str;
}
-char*
+std::string
win32getshell(const char* path)
{
char* path_env;
}
}
- return sh;
+ std::string result = sh ? sh : "";
+ free(sh);
+ return result;
}
void
STARTUPINFO si;
memset(&si, 0x00, sizeof(si));
- char* sh = win32getshell(path);
- if (sh) {
- path = sh;
+ std::string sh = win32getshell(path);
+ if (!sh.empty()) {
+ path = sh.c_str();
}
si.cb = sizeof(STARTUPINFO);
}
int length;
- char* args = win32argvtos(sh, argv, &length);
+ const char* prefix = sh.empty() ? nullptr : sh.c_str();
+ char* args = win32argvtos(prefix, argv, &length);
const char* ext = strrchr(path, '.');
char full_path_win_ext[MAX_PATH] = {0};
add_exe_ext_if_no_to_fullpath(full_path_win_ext, MAX_PATH, ext, path);
#include "system.hpp"
+#include <string>
+
struct Context;
int execute(const char* const* argv, int fd_out, int fd_err, pid_t* pid);
void print_command(FILE* fp, const char* const* argv);
char* format_command(const char* const* argv);
+
+#ifdef _WIN32
+char* win32argvtos(const char* prefix, const char* const* argv, int* length);
+std::string win32getshell(const char* path);
+int win32execute(const char* path,
+ const char* const* argv,
+ int doreturn,
+ int fd_stdout,
+ int fd_stderr);
+void add_exe_ext_if_no_to_fullpath(char* full_path_win_ext,
+ size_t max_size,
+ const char* ext,
+ const char* path);
+#endif
STARTUPINFO si;
memset(&si, 0x00, sizeof(si));
- char* path =
+ char* exe_path =
find_executable_in_path(args[0].c_str(), nullptr, getenv("PATH"));
- if (!path) {
- path = x_strdup(args[0].c_str());
+ std::string path = exe_path ? exe_path : "";
+ free(exe_path);
+ if (path.empty()) {
+ path = args[0];
}
- char* sh = win32getshell(path);
- if (sh) {
+ std::string sh = win32getshell(path.c_str());
+ if (!sh.empty()) {
path = sh;
}
char* win32args;
if (!cmd) {
int length;
- win32args = win32argvtos(sh, argv.data(), &length);
+ const char* prefix = sh.empty() ? nullptr : sh.c_str();
+ win32args = win32argvtos(prefix, argv.data(), &length);
} else {
win32args = (char*)command; // quoted
}
- BOOL ret =
- CreateProcess(path, win32args, NULL, NULL, 1, 0, NULL, NULL, &si, &pi);
- free(path);
+ BOOL ret = CreateProcess(
+ path.c_str(), win32args, NULL, NULL, 1, 0, NULL, NULL, &si, &pi);
CloseHandle(pipe_out[1]);
free(win32args);
if (!cmd) {
#ifndef O_BINARY
# define O_BINARY 0
#endif
-
-#ifdef _WIN32
-char* win32argvtos(const char* prefix, const char* const* argv, int* length);
-char* win32getshell(const char* path);
-int win32execute(const char* path,
- const char* const* argv,
- int doreturn,
- int fd_stdout,
- int fd_stderr);
-void add_exe_ext_if_no_to_fullpath(char* full_path_win_ext,
- size_t max_size,
- const char* ext,
- const char* path);
-#endif