Whoami: Rewrite whoami using getlogin

This commit is contained in:
Bananymous 2024-05-23 15:44:21 +03:00
parent 06f4b0b29a
commit cc2cc2849e
1 changed files with 3 additions and 5 deletions

View File

@ -1,16 +1,14 @@
#include <pwd.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
int main() int main()
{ {
auto* pw = getpwuid(geteuid()); char* login = getlogin();
if (pw == nullptr) if (login == nullptr)
{ {
printf("unknown user %d\n", geteuid()); printf("unknown user %d\n", geteuid());
return 1; return 1;
} }
printf("%s\n", pw->pw_name); printf("%s\n", login);
endpwent();
return 0; return 0;
} }