--- 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 _AT_@ -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 _AT_@ -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 --2fHTh5uZTiUOsy+g--Received on Mon Sep 17 2001 - 00:00:00 CEST
This archive was generated by hypermail 2.3.0 : Tue Aug 20 2013 - 07:12:03 CEST