13
0

force IFS=/ when calling path_expand, so that whitespace in paths doesn't cause wordexp() to get the wrong idea

git-svn-id: svn://localhost/ardour2/branches/3.0@10530 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2011-11-10 19:00:54 +00:00
parent bcf500a351
commit 80ec3fb37e

View File

@ -25,6 +25,7 @@
#include <cstdio> /* for sprintf */
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
@ -285,9 +286,27 @@ path_expand (string path)
string ret = path;
wordexp_t expansion;
switch (wordexp (path.c_str(), &expansion, WRDE_NOCMD|WRDE_UNDEF)) {
/* force field expansion to avoid use whitespace, since we know this is
* a path
*/
char *oifs = getenv ("IFS");
setenv ("IFS", "/", 1);
int result = wordexp (path.c_str(), &expansion, WRDE_NOCMD|WRDE_UNDEF);
if (oifs) {
setenv ("IFS", oifs, 1);
} else {
unsetenv ("IFS");
}
switch (result) {
case 0:
break;
case WRDE_NOSPACE:
/* see docs on wordexp() */
wordfree (&expansion);
/* fallthru */
default:
error << string_compose (_("illegal or badly-formed string used for path (%1)"), path) << endmsg;
goto out;