3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-25 01:55:33 +00:00

Added run_command() api to replace system() and popen()

This commit is contained in:
Clifford Wolf 2014-10-12 10:57:15 +02:00
parent d2b8b48bf3
commit b1596bc0e7
6 changed files with 104 additions and 92 deletions

View file

@ -165,20 +165,9 @@ struct Vhdl2verilogPass : public Pass {
log("Running '%s'..\n", command.c_str());
errno = ENOMEM; // popen does not set errno if memory allocation fails, therefore set it by hand
f = popen(command.c_str(), "r");
if (f == NULL)
log_error("Opening pipe to `%s' for reading failed: %s\n", command.c_str(), strerror(errno));
char logbuf[1024];
while (fgets(logbuf, 1024, f) != NULL)
log("%s", logbuf);
int ret = pclose(f);
if (ret < 0)
log_error("Closing pipe to `%s' failed: %s\n", command.c_str(), strerror(errno));
if (WEXITSTATUS(ret) != 0)
log_error("Execution of command \"%s\" failed: the shell returned %d\n", command.c_str(), WEXITSTATUS(ret));
int ret = run_command(command, [](const std::string &line) { log("%s", line.c_str()); });
if (ret != 0)
log_error("Execution of command \"%s\" failed: return code %d.\n", command.c_str(), ret);
if (out_file.empty()) {
std::ifstream ff;
@ -189,7 +178,7 @@ struct Vhdl2verilogPass : public Pass {
}
log_header("Removing temp directory `%s':\n", tempdir_name);
if (system(stringf("rm -rf '%s'", tempdir_name).c_str()) != 0)
if (run_command(stringf("rm -rf '%s'", tempdir_name).c_str()) != 0)
log_error("Execution of \"rm -rf '%s'\" failed!\n", tempdir_name);
log_pop();