Whoami: Rewrite whoami using getlogin
This commit is contained in:
parent
06f4b0b29a
commit
cc2cc2849e
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue