home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
zip
/
mint
/
mntlib16.lzh
/
MNTLIB16
/
GETHOSTN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-03
|
880b
|
47 lines
/* gethostname -- for now, fake by looking in environment */
/* (written by Eric R. Smith, placed in the public domain) */
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#define MAXLEN 127
int
gethostname(buf, len)
char *buf;
size_t len;
{
char *foo;
char xbuf[MAXLEN+1];
int fd, r;
foo = getenv("HOSTNAME");
if (!foo) {
/* try looking for the file /local/hostname; if it's present,
* it contains the name, otherwise we punt
*/
fd = open("/local/hostname", O_RDONLY);
if (fd >= 0) {
r = read(fd, xbuf, MAXLEN);
if (r > 0) {
xbuf[r] = 0;
foo = xbuf;
while (*foo) {
if (*foo == '\r' || *foo == '\n')
*foo = 0;
foo++;
}
foo = xbuf;
}
close(fd);
}
}
if (!foo)
foo = "unknown";
strncpy(buf, foo, len);
return 0;
}