2023-05-06 04:39:44 +00:00
|
|
|
#include "command.h"
|
|
|
|
#include "lslib.h"
|
2023-05-01 04:31:13 +00:00
|
|
|
|
|
|
|
#include <pwd.h>
|
2023-05-06 04:39:44 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2023-05-01 04:31:13 +00:00
|
|
|
|
2023-05-01 22:43:32 +00:00
|
|
|
static void help(void) {
|
2023-05-01 04:31:13 +00:00
|
|
|
printf("Usage: whoami\n\n");
|
|
|
|
printf("Print the username associated with the current effective user id\n");
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2023-05-15 14:57:33 +00:00
|
|
|
COMMAND(whoami_main) {
|
2023-05-04 20:10:37 +00:00
|
|
|
|
|
|
|
uid_t usr;
|
|
|
|
struct passwd* passwd;
|
|
|
|
|
2023-05-01 22:43:32 +00:00
|
|
|
parse_help(argc, argv, help);
|
2023-05-01 04:31:13 +00:00
|
|
|
|
2023-05-04 20:10:37 +00:00
|
|
|
usr = getuid();
|
|
|
|
passwd = getpwuid(usr);
|
|
|
|
|
2023-05-01 04:31:13 +00:00
|
|
|
if (passwd == NULL) {
|
|
|
|
printf("\x1b[1;91myou do not exist.\n");
|
|
|
|
} else {
|
|
|
|
printf("%s\n", passwd->pw_name);
|
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|