morpheus-base

morpheus base system
git clone git://git.2f30.org/morpheus-base
Log | Files | Refs

hostname.c (542B)


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