mirror of https://github.com/YosysHQ/yosys.git
handle quotes and check return value
This commit is contained in:
parent
1b403b82d7
commit
8557455411
|
@ -32,8 +32,8 @@ struct SetenvPass : public Pass {
|
||||||
log("\n");
|
log("\n");
|
||||||
log(" setenv name value\n");
|
log(" setenv name value\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
log("Set the given environment variable on the current process. String values must be\n");
|
log("Set the given environment variable on the current process. Values containing\n");
|
||||||
log("passed in double quotes (\").\n");
|
log("whitespace must be passed in double quotes (\").\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
}
|
}
|
||||||
void execute(std::vector<std::string> args, [[maybe_unused]] RTLIL::Design *design) override
|
void execute(std::vector<std::string> args, [[maybe_unused]] RTLIL::Design *design) override
|
||||||
|
@ -41,10 +41,15 @@ struct SetenvPass : public Pass {
|
||||||
if(args.size() != 3)
|
if(args.size() != 3)
|
||||||
log_cmd_error("Wrong number of arguments given.\n");
|
log_cmd_error("Wrong number of arguments given.\n");
|
||||||
|
|
||||||
|
std::string name = args[1];
|
||||||
|
std::string value = args[2];
|
||||||
|
if (value.front() == '\"' && value.back() == '\"') value = value.substr(1, value.size() - 2);
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
_putenv_s(args[1].c_str(), args[2].c_str());
|
_putenv_s(name.c_str(), value.c_str());
|
||||||
#else
|
#else
|
||||||
setenv(args[1].c_str(), args[2].c_str(), 1);
|
if (setenv(name.c_str(), value.c_str(), 1))
|
||||||
|
log_cmd_error("Invalid name \"%s\".\n", name.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue