aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-03-18 10:36:22 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-03-18 10:36:22 +1300
commit79807255feef41b15e91f5c0e82124f83c582517 (patch)
treec799b900fcadca5c736ac5a2ad98462f594a6209
parentWrote whoami(1) (diff)
downloadtunics-79807255feef41b15e91f5c0e82124f83c582517.tar.gz
tunics-79807255feef41b15e91f5c0e82124f83c582517.zip
Add hostname(1) implementation
-rw-r--r--.gitignore1
-rw-r--r--Makefile7
-rw-r--r--hostname.c13
-rw-r--r--hostname.h9
4 files changed, 28 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index a3a035a..1e2eb3c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+hostname
ls
pwd
sort
diff --git a/Makefile b/Makefile
index a93df43..cdb151a 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,10 @@
CC = clang
CFLAGS = -std=c90 -Weverything
-all : ls pwd sort whoami
+all : hostname ls pwd sort whoami
+
+hostname : hostname.c hostname.h
+ $(CC) $(CFLAGS) hostname.c -o hostname
ls : ls.c ls.h
$(CC) $(CFLAGS) ls.c -o ls
@@ -19,5 +22,5 @@ whoami : whoami.c whoami.h
clean :
rm -f -- *.o
- rm -f ls pwd sort whoami
+ rm -f hostname ls pwd sort whoami
diff --git a/hostname.c b/hostname.c
new file mode 100644
index 0000000..532fc16
--- /dev/null
+++ b/hostname.c
@@ -0,0 +1,13 @@
+#include "hostname.h"
+
+int main(void) {
+ struct utsname *name;
+ name = malloc(sizeof(struct utsname));
+ if (uname(name) == -1) {
+ perror("uname");
+ exit(EXIT_FAILURE);
+ }
+ fprintf(stdout, "%s\n", name->nodename);
+ exit(EXIT_SUCCESS);
+}
+
diff --git a/hostname.h b/hostname.h
new file mode 100644
index 0000000..4eb0b32
--- /dev/null
+++ b/hostname.h
@@ -0,0 +1,9 @@
+#ifndef __HOSTNAME_H
+#define __HOSTNAME_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/utsname.h>
+
+#endif
+