aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/src/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'svg-flatten/src/util.cpp')
-rw-r--r--svg-flatten/src/util.cpp41
1 files changed, 25 insertions, 16 deletions
diff --git a/svg-flatten/src/util.cpp b/svg-flatten/src/util.cpp
index d9a5a09..0597360 100644
--- a/svg-flatten/src/util.cpp
+++ b/svg-flatten/src/util.cpp
@@ -2,6 +2,7 @@
#include <sys/types.h>
#include <string>
#include <iostream>
+#include <vector>
#ifndef NOFORK
#include <pwd.h>
@@ -11,16 +12,24 @@
#include "util.h"
-using namespace std;
-
#ifndef NOFORK
-int gerbolyze::run_cargo_command(const char *cmd_name, const char *cmdline[], const char *envvar) {
+int gerbolyze::run_cargo_command(const char *cmd_name, std::vector<std::string> &cmdline, const char *envvar) {
+
+ //std::cerr << "Running command: " << cmd_name << " ";
+ std::vector<const char *> cmdline_c = {nullptr};
+ for (std::string &s : cmdline) {
+ //std::cerr << s << " ";
+ cmdline_c.push_back(s.c_str());
+ }
+ cmdline_c.push_back(nullptr);
+ //std::cerr << std::endl;
+
const char *homedir;
if ((homedir = getenv("HOME")) == NULL) {
homedir = getpwuid(getuid())->pw_dir;
}
- string homedir_s(homedir);
- string cargo_bin_dir = homedir_s + "/.cargo/bin/" + cmd_name;
+ std::string homedir_s(homedir);
+ std::string cargo_bin_dir = homedir_s + "/.cargo/bin/" + cmd_name;
bool found = false;
int proc_rc = -1;
@@ -31,36 +40,36 @@ int gerbolyze::run_cargo_command(const char *cmd_name, const char *cmdline[], co
if ((envvar_val = getenv(envvar)) == NULL) {
continue;
} else {
- cmdline[0] = envvar_val;
+ cmdline_c[0] = envvar_val;
}
break;
case 1:
- cmdline[0] = cmd_name;
+ cmdline_c[0] = cmd_name;
break;
case 2:
- cmdline[0] = cargo_bin_dir.c_str();
+ cmdline_c[0] = cargo_bin_dir.c_str();
break;
}
struct subprocess_s subprocess;
- int rc = subprocess_create(cmdline, subprocess_option_inherit_environment, &subprocess);
+ int rc = subprocess_create(cmdline_c.data(), subprocess_option_inherit_environment, &subprocess);
if (rc) {
- cerr << "Error calling " << cmd_name << endl;
+ std::cerr << "Error calling " << cmd_name << std::endl;
return EXIT_FAILURE;
}
proc_rc = -1;
rc = subprocess_join(&subprocess, &proc_rc);
if (rc) {
- cerr << "Error calling " << cmd_name << endl;
+ std::cerr << "Error calling " << cmd_name << std::endl;
return EXIT_FAILURE;
}
rc = subprocess_destroy(&subprocess);
if (rc) {
- cerr << "Error calling " << cmd_name << endl;
+ std::cerr << "Error calling " << cmd_name << std::endl;
return EXIT_FAILURE;
}
@@ -73,21 +82,21 @@ int gerbolyze::run_cargo_command(const char *cmd_name, const char *cmdline[], co
}
if (!found) {
- cerr << "Error: Cannot find " << cmd_name << ". Is it installed and in $PATH?" << endl;
+ std::cerr << "Error: Cannot find " << cmd_name << ". Is it installed and in $PATH?" << std::endl;
return EXIT_FAILURE;
}
if (proc_rc) {
- cerr << cmd_name << " returned an error code: " << proc_rc << endl;
+ std::cerr << cmd_name << " returned an error code: " << proc_rc << std::endl;
return EXIT_FAILURE;
}
return 0;
}
#else
-int gerbolyze::run_cargo_command(const char *cmd_name, const char *cmdline[], const char *envvar) {
+int gerbolyze::run_cargo_command(const char *cmd_name, std::vector<std::string> &cmdline, const char *envvar) {
(void) cmd_name, (void) cmdline, (void) envvar;
- cerr << "Error: Cannot spawn " << cmd_name << " subprocess since binary was built with fork/exec disabled (-DNOFORK=1)" << endl;
+ std::cerr << "Error: Cannot spawn " << cmd_name << " subprocess since binary was built with fork/exec disabled (-DNOFORK=1)" << std::endl;
return EXIT_FAILURE;
}
#endif