summaryrefslogtreecommitdiff
path: root/package/sash/src/hostname.c
blob: 5faeabce53b73af29e73f7c9ef328c2b617d7c8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* hostname.c - poe@daimi.aau.dk */

#include "sash.h"

#include <sys/types.h>
#include <sys/param.h>
#include <stdio.h>
#include <unistd.h>

void do_hostname(int argc, char **argv)
{
	char hn[PATHLEN + 1];

	if(argc >= 2) {
		if(strlen(argv[1]) > PATHLEN) {
			printf("That name is too long.\n");
		} else {
			sethostname(argv[1], strlen(argv[1]));
		}
	} else {
		gethostname(hn, PATHLEN);
		printf("%s\n", hn);
	}
}