Escape spaces in file names for `wordexp` v2 but just append to stringstream

pull/408/head
jackun 3 years ago
parent a4a5950ddf
commit e0f79d9435
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -239,22 +239,22 @@ parse_path(const char *str)
#ifdef _XOPEN_SOURCE
// Expand ~/ to home dir
if (str[0] == '~') {
std::string s = str;
size_t n = 0;
std::stringstream s;
wordexp_t e;
int ret;
while ((n = s.find_first_of(" ", n)) != std::string::npos) {
s = s.replace(n, 1, "\\ ");
n += 2;
if (!(ret = wordexp(str, &e, 0))) {
for(size_t i = 0; i < e.we_wordc; i++)
{
if (i > 0)
s << " ";
s << e.we_wordv[i];
}
}
if (!(ret = wordexp(s.c_str(), &e, 0)))
s = e.we_wordv[0];
wordfree(&e);
if (!ret)
return s;
return s.str();
}
#endif
return str;

Loading…
Cancel
Save