1: #include <errno.h> 2: #include <sys/types.h> 3: #include <sys/file.h> 4: 5: #define HOSTNAMESIZE 32 6: #ifndef hostnamelen 7: #define hostnamelen hnamelen 8: #endif 9: extern errno; 10: static char hostname[HOSTNAMESIZE]; 11: static int hostnamelen = HOSTNAMESIZE; 12: 13: gethostname(p, len) 14: register char *p; 15: { 16: int fd; 17: register i; 18: register char *q = hostname; 19: 20: if ((fd = open("/etc/localhostname", FATT_RDONLY)) == -1) { 21: errno = EFAULT; 22: return(-1); 23: } 24: hostnamelen = read(fd, &hostname, sizeof hostname); 25: if (hostnamelen < 0) { 26: errno = EFAULT; 27: return(-1); 28: } 29: else 30: for (i = 0; i < (len < hostnamelen ? len : hostnamelen); i++) 31: if (*q == '\n') { 32: *p = '\0'; 33: break; 34: } 35: else 36: *p++ = *q++; 37: return(0); 38: }