1: /* pathalias -- by steve bellovin, as told to peter honeyman */
   2: #ifndef lint
   3: static char *sccsid = "@(#)local.c	9.1.1 93/12/31";
   4: #endif /* lint */
   5: 
   6: #include <stdio.h>
   7: #include "config.h"
   8: 
   9: #ifdef  UNAME
  10: #include <sys/utsname.h>
  11: 
  12: char    *
  13: local()
  14: {
  15:     static struct utsname utsname;
  16: 
  17:     uname(&utsname);
  18:     return(utsname.nodename);
  19: }
  20: 
  21: #else /* !UNAME */
  22: 
  23: char    *
  24: local()
  25: {
  26:     static char lname[64];
  27: 
  28:     gethostname(lname, sizeof(lname));
  29:     return(lname);
  30: }
  31: 
  32: #ifndef GETHOSTNAME
  33: 
  34: static
  35: gethostname(name, len)
  36: char    *name;
  37: {
  38:     FILE    *whoami, *fopen(), *popen();
  39:     char    *ptr, *index();
  40: 
  41:     *name = '\0';
  42: 
  43:     /* try /etc/whoami */
  44:     if ((whoami = fopen("/etc/whoami", "r")) != 0) {
  45:         (void) fgets(name, len, whoami);
  46:         (void) fclose(whoami);
  47:         if ((ptr = index(name, '\n')) != 0)
  48:             *ptr = '\0';
  49:     }
  50:     if (*name)
  51:         return 0;
  52: 
  53:     /* try /usr/include/whoami.h */
  54:     if ((whoami = fopen("/usr/include/whoami.h", "r")) != 0) {
  55:         while (!feof(whoami)) {
  56:             char    buf[100];
  57: 
  58:             if (fgets(buf, 100, whoami) == 0)
  59:                 break;
  60:             if (sscanf(buf, "#define sysname \"%[^\"]\"", name))
  61:                 break;
  62:         }
  63:         (void) fclose(whoami);
  64:         if (*name)
  65:             return 0;
  66:     }
  67: 
  68:     /* ask uucp */
  69:     if ((whoami = popen("uuname -l", "r")) != 0) {
  70:         (void) fgets(name, len, whoami);
  71:         (void) pclose(whoami);
  72:         if ((ptr = index(name, '\n')) != 0)
  73:             *ptr = '\0';
  74:     }
  75:     if (*name)
  76:         return 0;
  77: 
  78:     /* aw hell, i give up!  is this really unix? */
  79:     return -1;
  80: }
  81: #endif /* GETHOSTNAME */
  82: #endif /* UNAME */

Defined functions

gethostname defined in line 34; used 1 times
  • in line 28
local defined in line 23; used 2 times

Defined variables

sccsid defined in line 3; never used
Last modified: 1994-01-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3017
Valid CSS Valid XHTML 1.0 Strict