Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/* posix */
2
#include <sys/types.h>
3
#include <unistd.h>
4
#include <stdlib.h>
5
#include <fcntl.h>
6
#include <string.h>
7
 
8
int
9
gethostname(char *name, int namelen)
10
{
11
	int n, fd;
12
	char buf[128];
13
 
14
	fd = open("/dev/sysname", O_RDONLY);
15
	if(fd < 0)
16
		return -1;
17
	n = read(fd, buf, sizeof(buf)-1);
18
	close(fd);
19
	if(n <= 0)
20
		return -1;
21
	buf[n] = 0;
22
	strncpy(name, buf, namelen);
23
	name[namelen-1] = 0;
24
	return 0;
25
}