force IFS=/ when calling path_expand, so that whitespace in paths doesn't cause worde...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 10 Nov 2011 19:00:54 +0000 (19:00 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 10 Nov 2011 19:00:54 +0000 (19:00 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@10530 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/utils.cc

index 63125ed8cb8652ab0adafbe79489fa00d872c95c..c1192c4fe123acd645572cddd1bd08acbd54b6b6 100644 (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;