Skip to content

Commit efa0a51

Browse files
committed
Quote arguments with spaces to CA65/LD65 on windows.
1 parent 2368ecc commit efa0a51

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/compiler/os.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,30 @@ void os::init()
112112

113113
int os::prog_exec(std::string exe, std::vector<std::string> &args)
114114
{
115-
// Create a vector with C pointers
116115
std::vector<const char *> pargs;
116+
#ifdef _WIN32
117+
// Escape any string with spaces in it:
118+
std::vector<std::string> esc_args;
117119
for(const auto &s : args)
120+
{
121+
if(s.find(' ') != s.npos)
122+
esc_args.push_back("\"" + s + "\"");
123+
else
124+
esc_args.push_back(s);
125+
}
126+
// Create a vector with C pointers
127+
for(const auto &s : esc_args)
118128
pargs.push_back(s.c_str());
119129
pargs.push_back(nullptr);
120-
121-
// Execute the program
122-
#ifdef _WIN32
123130
// win32 has the "spawn" function that calls the program and waits
124131
// for termination:
125132
return _spawnv(_P_WAIT, exe.c_str(), (char **)pargs.data());
126133
#else
134+
// Create a vector with C pointers
135+
for(const auto &s : args)
136+
pargs.push_back(s.c_str());
137+
pargs.push_back(nullptr);
138+
127139
// We reimplement "system" to allow passing arguments without escaping:
128140

129141
// Ignore INT and QUIT signals in the parent process:

0 commit comments

Comments
 (0)