summaryrefslogtreecommitdiffstats
path: root/usr/klibc/gethostname.c
blob: 120edd94317088cdcd822111530f78825047c0ca (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
25
/*
 * gethostname.c
 */

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

int gethostname(char *name, size_t len)
{
	struct utsname un;

	if (uname(&un))
		return -1;

	if (len < strlen(un.nodename) + 1) {
		errno = EINVAL;
		return -1;
	}

	strcpy(name, un.nodename);

	return 0;
}