summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/lib/gethostname.c
blob: c3d2f3d5e3b27aa9bd24cb29188a2bfb56d96a4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#define _GNU_SOURCE

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

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