Uninitialized vector entry?
[minix3.git] / lib / ip / gethostname.c
blob74cb13588fea9506c35d458a68597feed807a654
1 /* gethostname(2) system call emulation */
3 #include <sys/types.h>
4 #include <fcntl.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <net/gen/netdb.h>
10 #define HOSTNAME_FILE "/etc/hostname.file"
12 int gethostname(char *buf, size_t len)
14 int fd;
15 int r;
16 char *nl;
18 if ((fd= open(HOSTNAME_FILE, O_RDONLY)) < 0) return -1;
20 r= read(fd, buf, len);
21 close(fd);
22 if (r == -1) return -1;
24 buf[len-1]= '\0';
25 if ((nl= strchr(buf, '\n')) != NULL) *nl= '\0';
26 return 0;