diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-03-17 23:54:19 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-03-17 23:54:19 +1300 |
commit | 52306a7f6ac1dd89a0dad17024db222dd36e80a9 (patch) | |
tree | 5727030d122490ebfb5fd55b898139007266bd82 | |
parent | Use sizeof rather than constant (diff) | |
download | tunics-52306a7f6ac1dd89a0dad17024db222dd36e80a9.tar.gz tunics-52306a7f6ac1dd89a0dad17024db222dd36e80a9.zip |
Wrote whoami(1)
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | whoami.c | 14 | ||||
-rw-r--r-- | whoami.h | 10 |
4 files changed, 30 insertions, 2 deletions
@@ -1,3 +1,4 @@ ls pwd sort +whoami @@ -3,7 +3,7 @@ CC = clang CFLAGS = -std=c90 -Weverything -all : ls pwd sort +all : ls pwd sort whoami ls : ls.c ls.h $(CC) $(CFLAGS) ls.c -o ls @@ -14,7 +14,10 @@ pwd : pwd.c pwd.h sort : sort.c sort.h $(CC) $(CFLAGS) sort.c -o sort +whoami : whoami.c whoami.h + $(CC) $(CFLAGS) whoami.c -o whoami + clean : rm -f -- *.o - rm -f ls pwd sort + rm -f ls pwd sort whoami diff --git a/whoami.c b/whoami.c new file mode 100644 index 0000000..b692abe --- /dev/null +++ b/whoami.c @@ -0,0 +1,14 @@ +#include "whoami.h" + +int main(void) { + struct passwd *p; + + if ((p = getpwuid(getuid())) == NULL) { + exit(EXIT_FAILURE); + } + + printf("%s\n", p->pw_name); + + exit(EXIT_SUCCESS); +} + diff --git a/whoami.h b/whoami.h new file mode 100644 index 0000000..f61a04c --- /dev/null +++ b/whoami.h @@ -0,0 +1,10 @@ +#ifndef __WHOAMI_H + +#include <pwd.h> +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> + +#endif + |