Skip to content

Commit

Permalink
handle quotes and check return value
Browse files Browse the repository at this point in the history
  • Loading branch information
nakengelhardt committed Dec 6, 2024
1 parent 1b403b8 commit 8557455
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions passes/cmds/setenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,26 @@ struct SetenvPass : public Pass {
log("\n");
log(" setenv name value\n");
log("\n");
log("Set the given environment variable on the current process. String values must be\n");
log("passed in double quotes (\").\n");
log("Set the given environment variable on the current process. Values containing\n");
log("whitespace must be passed in double quotes (\").\n");
log("\n");
}
void execute(std::vector<std::string> args, [[maybe_unused]] RTLIL::Design *design) override
{
if(args.size() != 3)
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)
_putenv_s(args[1].c_str(), args[2].c_str());
_putenv_s(name.c_str(), value.c_str());
#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

}
} SetenvPass;

Expand Down

0 comments on commit 8557455

Please sign in to comment.