1/* See LICENSE file for copyright and license details. */
2
3
4#include <stdio.h>
5#include <string.h>
6#include <unistd.h>
7
8#include "util.h"
9
10static void
11usage(void)
12{
13 eprintf("usage: %s [name]\n", argv0);
14}
15
16// ?man hostname: show or set hostname
17// ?man arguments: name
18// ?man display or configure the system hostname
19int
20main(int argc, char *argv[])
21{
22 char host[HOST_NAME_MAX + 1];
23
24 ARGBEGIN {
25 default:
26 usage();
27 } ARGEND
28
29 if (!argc) {
30 if (gethostname(host, sizeof(host)) < 0)
31 eprintf("gethostname:");
32 puts(host);
33 } else if (argc == 1) {
34 if (sethostname(argv[0], strlen(argv[0])) < 0)
35 eprintf("sethostname:");
36 } else {
37 usage();
38 }
39
40 return fshut(stdout, "<stdout>");
41}