aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/file-system.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/file-system.cc')
-rw-r--r--src/libutil/file-system.cc14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libutil/file-system.cc b/src/libutil/file-system.cc
index 8c69c9864..1d3eba58f 100644
--- a/src/libutil/file-system.cc
+++ b/src/libutil/file-system.cc
@@ -18,15 +18,19 @@ namespace fs = std::filesystem;
namespace nix {
+Path getCwd() {
+ char buf[PATH_MAX];
+ if (!getcwd(buf, sizeof(buf))) {
+ throw SysError("cannot get cwd");
+ }
+ return Path(buf);
+}
+
Path absPath(Path path, std::optional<PathView> dir, bool resolveSymlinks)
{
if (path.empty() || path[0] != '/') {
if (!dir) {
- char buf[PATH_MAX];
- if (!getcwd(buf, sizeof(buf))) {
- throw SysError("cannot get cwd");
- }
- path = concatStrings(buf, "/", path);
+ path = concatStrings(getCwd(), "/", path);
} else {
path = concatStrings(*dir, "/", path);
}