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