diff options
author | Tyler Murphy <tylerm@tylerm.dev> | 2023-05-01 00:31:13 -0400 |
---|---|---|
committer | Tyler Murphy <tylerm@tylerm.dev> | 2023-05-01 00:31:13 -0400 |
commit | 317f7bf35716f7059511f42f1f4aba7d47fcfd01 (patch) | |
tree | 2ea2c6ec05eff6bd8a3d139b04834dfb624754b8 /src/commands/whoami.c | |
parent | update ed help message to make s commands make more sense (diff) | |
download | lazysphere-317f7bf35716f7059511f42f1f4aba7d47fcfd01.tar.gz lazysphere-317f7bf35716f7059511f42f1f4aba7d47fcfd01.tar.bz2 lazysphere-317f7bf35716f7059511f42f1f4aba7d47fcfd01.zip |
tee, whoami, wc
Diffstat (limited to '')
-rw-r--r-- | src/commands/whoami.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/commands/whoami.c b/src/commands/whoami.c new file mode 100644 index 0000000..efc9bcd --- /dev/null +++ b/src/commands/whoami.c @@ -0,0 +1,24 @@ +#include "../command.h" + +#include <pwd.h> +#include <sys/types.h> +#include <unistd.h> + +static void help() { + printf("Usage: whoami\n\n"); + printf("Print the username associated with the current effective user id\n"); + exit(EXIT_SUCCESS); +} + +COMMAND(whoami) { + if (argc > 0 && streql("--help", argv[0])) help(); + + uid_t usr = getuid(); + struct passwd* passwd = getpwuid(usr); + if (passwd == NULL) { + printf("\x1b[1;91myou do not exist.\n"); + } else { + printf("%s\n", passwd->pw_name); + } + return EXIT_SUCCESS; +} |