• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <unistd.h>
2 #include <sys/utsname.h>
3 
gethostname(char * name,size_t len)4 int gethostname(char *name, size_t len)
5 {
6 	size_t i;
7 	struct utsname uts;
8 	if (uname(&uts)) return -1;
9 	if (len > sizeof uts.nodename) len = sizeof uts.nodename;
10 	for (i=0; i<len && (name[i] = uts.nodename[i]); i++);
11 	if (i && i==len) name[i-1] = 0;
12 	return 0;
13 }
14