diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2022-04-20 16:53:16 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2022-04-20 16:53:16 +0000 |
commit | 3c220442ffb9c951f42185479d34a1abf8596e9b (patch) | |
tree | 0c09315dec88c7e1f9a4aad0e744692d0f72dbe7 /src/libutil/util.cc | |
parent | 75b62e52600a44b42693944b50638bf580a2c86e (diff) | |
parent | ee57f91413c9d01f1027eccbe01f7706c94919ac (diff) |
Merge remote-tracking branch 'upstream/master' into fix-url-format
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r-- | src/libutil/util.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index d4379a0cf..b49c1e466 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -198,6 +198,17 @@ std::string_view baseNameOf(std::string_view path) } +std::string expandTilde(std::string_view path) +{ + // TODO: expand ~user ? + auto tilde = path.substr(0, 2); + if (tilde == "~/" || tilde == "~") + return getHome() + std::string(path.substr(1)); + else + return std::string(path); +} + + bool isInDir(std::string_view path, std::string_view dir) { return path.substr(0, 1) == "/" @@ -213,6 +224,15 @@ bool isDirOrInDir(std::string_view path, std::string_view dir) } +struct stat stat(const Path & path) +{ + struct stat st; + if (stat(path.c_str(), &st)) + throw SysError("getting status of '%1%'", path); + return st; +} + + struct stat lstat(const Path & path) { struct stat st; |