Store original working directory before changing, for later turning user args into absolute paths
This commit is contained in:
@@ -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, "/");
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ extern std::string path_tildexpand(const std::string &s);
|
||||
/// we return an empty path in this case.
|
||||
extern std::string path_absolute(const std::string &s);
|
||||
/// Clean up path by removing duplicated / and resolving ../ + make it absolute
|
||||
extern std::string path_canon(const std::string &s);
|
||||
extern std::string path_canon(const std::string &s, const std::string *cwd=0);
|
||||
/// Use glob(3) to return the file names matching pattern inside dir
|
||||
extern std::vector<std::string> path_dirglob(const std::string &dir,
|
||||
const std::string pattern);
|
||||
|
||||
Reference in New Issue
Block a user