]> git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/unistd/gethostname.c
WASI libc prototype implementation.
[wasi-libc.git] / libc-top-half / musl / src / unistd / gethostname.c
1 #include <unistd.h>
2 #include <sys/utsname.h>
3
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 }