Store original working directory before changing, for later turning user args into absolute paths

This commit is contained in:
Jean-Francois Dockes
2013-06-06 14:05:26 +02:00
parent 77cba9d0b3
commit e77c510dfe
5 changed files with 35 additions and 7 deletions
+9 -4
View File
@@ -335,17 +335,22 @@ extern string path_absolute(const string &is)
}
#include <smallut.h>
extern string path_canon(const string &is)
extern string path_canon(const string &is, const string* cwd)
{
if (is.length() == 0)
return is;
string s = is;
if (s[0] != '/') {
char buf[MAXPATHLEN];
if (!getcwd(buf, MAXPATHLEN)) {
return string();
const char *cwdp = buf;
if (cwd) {
cwdp = cwd->c_str();
} else {
if (!getcwd(buf, MAXPATHLEN)) {
return string();
}
}
s = path_cat(string(buf), s);
s = path_cat(string(cwdp), s);
}
vector<string> elems;
stringToTokens(s, elems, "/");