From cc2cc2849e1ec5b053689168322aa5e3ec76232b Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 23 May 2024 15:44:21 +0300 Subject: [PATCH] Whoami: Rewrite whoami using getlogin --- userspace/whoami/main.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/userspace/whoami/main.cpp b/userspace/whoami/main.cpp index a042c569c7..514c0e78ae 100644 --- a/userspace/whoami/main.cpp +++ b/userspace/whoami/main.cpp @@ -1,16 +1,14 @@ -#include #include #include int main() { - auto* pw = getpwuid(geteuid()); - if (pw == nullptr) + char* login = getlogin(); + if (login == nullptr) { printf("unknown user %d\n", geteuid()); return 1; } - printf("%s\n", pw->pw_name); - endpwent(); + printf("%s\n", login); return 0; }