No manpage yet.
>From 3be9770128464a7d18978c448246c4b8c2c1e61d Mon Sep 17 00:00:00 2001
From: sin <s...@2f30.org>
Date: Mon, 19 Aug 2013 17:22:46 +0100
Subject: [PATCH] Add hostname(1)

---
 Makefile   |  1 +
 hostname.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 hostname.c

diff --git a/Makefile b/Makefile
index 3c613b0..d347aa5 100644
--- a/Makefile
+++ b/Makefile
@@ -46,6 +46,7 @@ SRC = \
        fold.c     \
        grep.c     \
        head.c     \
+       hostname.c \
        id.c       \
        kill.c     \
        ln.c       \
diff --git a/hostname.c b/hostname.c
new file mode 100644
index 0000000..e277e05
--- /dev/null
+++ b/hostname.c
@@ -0,0 +1,33 @@
+/* See LICENSE file for copyright and license details. */
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include "util.h"
+
+static void
+usage(void)
+{
+       eprintf("usage: %s name\n", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+       char buf[BUFSIZ];
+
+       ARGBEGIN {
+       default:
+               usage();
+       } ARGEND;
+
+       if (argc < 1) {
+               if (gethostname(buf, sizeof(buf)) < 0)
+                       eprintf("gethostname:");
+               printf("%s\n", buf);
+       } else {
+               if (sethostname(argv[0], strlen(argv[0])) < 0)
+                       eprintf("sethostname:");
+       }
+
+       return 0;
+}
-- 
1.8.2.3

Reply via email to