Skip to content

Commit 8557455

Browse files
committed
handle quotes and check return value
1 parent 1b403b8 commit 8557455

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

passes/cmds/setenv.cc

+10-5
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,26 @@ struct SetenvPass : public Pass {
3232
log("\n");
3333
log(" setenv name value\n");
3434
log("\n");
35-
log("Set the given environment variable on the current process. String values must be\n");
36-
log("passed in double quotes (\").\n");
35+
log("Set the given environment variable on the current process. Values containing\n");
36+
log("whitespace must be passed in double quotes (\").\n");
3737
log("\n");
3838
}
3939
void execute(std::vector<std::string> args, [[maybe_unused]] RTLIL::Design *design) override
4040
{
4141
if(args.size() != 3)
4242
log_cmd_error("Wrong number of arguments given.\n");
43+
44+
std::string name = args[1];
45+
std::string value = args[2];
46+
if (value.front() == '\"' && value.back() == '\"') value = value.substr(1, value.size() - 2);
4347

4448
#if defined(_WIN32)
45-
_putenv_s(args[1].c_str(), args[2].c_str());
49+
_putenv_s(name.c_str(), value.c_str());
4650
#else
47-
setenv(args[1].c_str(), args[2].c_str(), 1);
51+
if (setenv(name.c_str(), value.c_str(), 1))
52+
log_cmd_error("Invalid name \"%s\".\n", name.c_str());
4853
#endif
49-
54+
5055
}
5156
} SetenvPass;
5257

0 commit comments

Comments
 (0)