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