micro-utils/coreutils/whoami.c
Your Name 7eed71d9b2 mk
2023-10-13 15:34:16 +03:00

20 lines
311 B
C

#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
struct passwd *pw = getpwuid(getuid());
if (!pw) {
fprintf(stderr, "whoami: %s\n", strerror(errno));
return 1;
}
puts(pw->pw_name);
return 0;
}