summaryrefslogblamecommitdiff
path: root/src/unistd/gethostname.c
blob: a406c4eba5e61ab78522146e85edf44a70befe6a (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14













                                                                 
#include <unistd.h>
#include <sys/utsname.h>
#include <string.h>

int gethostname(char *name, size_t len)
{
	size_t i;
	struct utsname uts;
	if (uname(&uts)) return -1;
	if (len > sizeof uts.nodename) len = sizeof uts.nodename;
	for (i=0; i<len && (name[i] = uts.nodename[i]); i++);
	if (i==len) name[i-1] = 0;
	return 0;
}