diff options
author | akhropov <akhropov@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
commit | 298c6da79f1d8f35089a67f463f0b541bec36d9b (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/system/user.cpp | |
parent | 00afc96e9c0298054b7386fa7fb9e3cc3d67b974 (diff) | |
download | ydb-298c6da79f1d8f35089a67f463f0b541bec36d9b.tar.gz |
Restoring authorship annotation for <akhropov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system/user.cpp')
-rw-r--r-- | util/system/user.cpp | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/util/system/user.cpp b/util/system/user.cpp index 8c66a8ce95..83e89ea0a8 100644 --- a/util/system/user.cpp +++ b/util/system/user.cpp @@ -1,18 +1,18 @@ -#include "user.h" -#include "platform.h" -#include "defaults.h" +#include "user.h" +#include "platform.h" +#include "defaults.h" #include "env.h" - -#include <util/generic/yexception.h> - -#ifdef _win_ + +#include <util/generic/yexception.h> + +#ifdef _win_ #include "winint.h" -#else +#else #include <errno.h> #include <pwd.h> #include <unistd.h> -#endif - +#endif + TString GetUsername() { for (const auto& var : {"LOGNAME", "USER", "LNAME", "USERNAME"}) { TString val = GetEnv(var); @@ -21,19 +21,19 @@ TString GetUsername() { } } - TTempBuf nameBuf; - for (;;) { -#if defined(_win_) - DWORD len = (DWORD)Min(nameBuf.Size(), size_t(32767)); + TTempBuf nameBuf; + for (;;) { +#if defined(_win_) + DWORD len = (DWORD)Min(nameBuf.Size(), size_t(32767)); if (!GetUserNameA(nameBuf.Data(), &len)) { - DWORD err = GetLastError(); - if ((err == ERROR_INSUFFICIENT_BUFFER) && (nameBuf.Size() <= 32767)) - nameBuf = TTempBuf((size_t)len); - else - ythrow TSystemError(err) << " GetUserName failed"; - } else { + DWORD err = GetLastError(); + if ((err == ERROR_INSUFFICIENT_BUFFER) && (nameBuf.Size() <= 32767)) + nameBuf = TTempBuf((size_t)len); + else + ythrow TSystemError(err) << " GetUserName failed"; + } else { return TString(nameBuf.Data(), (size_t)(len - 1)); - } + } #elif defined(_bionic_) const passwd* pwd = getpwuid(geteuid()); @@ -43,16 +43,16 @@ TString GetUsername() { ythrow TSystemError() << TStringBuf(" getpwuid failed"); #else - passwd pwd; - passwd* tmpPwd; - int err = getpwuid_r(geteuid(), &pwd, nameBuf.Data(), nameBuf.Size(), &tmpPwd); + passwd pwd; + passwd* tmpPwd; + int err = getpwuid_r(geteuid(), &pwd, nameBuf.Data(), nameBuf.Size(), &tmpPwd); if (err == 0 && tmpPwd) { return TString(pwd.pw_name); } else if (err == ERANGE) { nameBuf = TTempBuf(nameBuf.Size() * 2); - } else { + } else { ythrow TSystemError(err) << " getpwuid_r failed"; - } -#endif - } -} + } +#endif + } +} |