diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-10-10 12:54:37 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-10-10 12:54:37 +0200 |
commit | e99bb9121787ae30a1872f63b326ce5c130ec7ef (patch) | |
tree | ecdd2b7ba575b0848d2770f8e74b40646f512c71 /src/libutil/util.cc | |
parent | d343c03edb8d4d2be7aca4f1a377544b3889b8b3 (diff) | |
parent | c3aaf3b8da1a925c569389f13a861816a781a3c8 (diff) |
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r-- | src/libutil/util.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 98a7ea397..9d6bec034 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -486,6 +486,16 @@ std::pair<AutoCloseFD, Path> createTempFile(const Path & prefix) } +std::string getUserName() +{ + auto pw = getpwuid(geteuid()); + std::string name = pw ? pw->pw_name : getEnv("USER", ""); + if (name.empty()) + throw Error("cannot figure out user name"); + return name; +} + + static Lazy<Path> getHome2([]() { Path homeDir = getEnv("HOME"); if (homeDir.empty()) { |