aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile7
-rw-r--r--whoami.c14
-rw-r--r--whoami.h10
4 files changed, 30 insertions, 2 deletions
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 <pwd.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+
+#endif
+