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: }

Defined functions

Defined variables

hostname defined in line 10; used 3 times
hostnamelen defined in line 11; never used

Defined macros

HOSTNAMESIZE defined in line 5; used 2 times
hostnamelen defined in line 7; used 5 times
Last modified: 1983-05-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 801
Valid CSS Valid XHTML 1.0 Strict