From 52306a7f6ac1dd89a0dad17024db222dd36e80a9 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 17 Mar 2016 23:54:19 +1300 Subject: Wrote whoami(1) --- .gitignore | 1 + Makefile | 7 +++++-- whoami.c | 14 ++++++++++++++ whoami.h | 10 ++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 whoami.c create mode 100644 whoami.h diff --git a/.gitignore b/.gitignore index 4951cbe..a3a035a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ ls pwd sort +whoami diff --git a/Makefile b/Makefile index eacea17..a93df43 100644 --- a/Makefile +++ b/Makefile @@ -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 +#include +#include +#include +#include + +#endif + -- cgit v1.2.3