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