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 <unistd.h>
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;
}