summaryrefslogtreecommitdiff
path: root/package/sash/src/hostname.c
diff options
context:
space:
mode:
Diffstat (limited to 'package/sash/src/hostname.c')
-rw-r--r--package/sash/src/hostname.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/package/sash/src/hostname.c b/package/sash/src/hostname.c
new file mode 100644
index 000000000..8841e7fa3
--- /dev/null
+++ b/package/sash/src/hostname.c
@@ -0,0 +1,24 @@
+/* hostname.c - poe@daimi.aau.dk */
+
+#include "sash.h"
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <stdio.h>
+#include <unistd.h>
+
+void do_hostname(int argc, char **argv)
+{
+ char hn[PATHLEN + 1];
+
+ if(argc >= 2) {
+ if(strlen(argv[1]) > PATHLEN) {
+ printf("That name is too long.\n");
+ } else {
+ sethostname(argv[1], strlen(argv[1]));
+ }
+ } else {
+ gethostname(hn, PATHLEN);
+ printf("%s\n", hn);
+ }
+}