source: trunk/minix/lib/ip/gethostname.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 489 bytes
Line 
1/* gethostname(2) system call emulation */
2
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>
9
10#define HOSTNAME_FILE "/etc/hostname.file"
11
12int gethostname(char *buf, size_t len)
13{
14 int fd;
15 int r;
16 char *nl;
17
18 if ((fd= open(HOSTNAME_FILE, O_RDONLY)) < 0) return -1;
19
20 r= read(fd, buf, len);
21 close(fd);
22 if (r == -1) return -1;
23
24 buf[len-1]= '\0';
25 if ((nl= strchr(buf, '\n')) != NULL) *nl= '\0';
26 return 0;
27}
Note: See TracBrowser for help on using the repository browser.