home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / auucp+-1.02 / fuucp_plus_src.lzh / pathalias / local.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-17  |  1.8 KB  |  105 lines

  1. /* pathalias -- by steve bellovin, as told to peter honeyman */
  2. #ifndef lint
  3. static char    *sccsid = "@(#)local.c    9.2 88/06/10";
  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.     extern int uname();
  17.  
  18.     (void) uname(&utsname);
  19.     return(utsname.nodename);
  20. }
  21.  
  22. #else /* !UNAME */
  23.  
  24. char    *
  25. local()
  26. {
  27.     static char lname[64];
  28.     extern int gethostname();
  29.  
  30.     (void) gethostname(lname, (int) sizeof(lname));
  31.     lname[sizeof(lname) - 1] = 0;
  32.     return(lname);
  33. }
  34.  
  35. #ifndef GETHOSTNAME
  36.  
  37. STATIC int
  38. gethostname(name, len)
  39.     char *name;
  40.     int len;
  41. {
  42. #ifndef AMIGA
  43.     FILE *whoami;
  44.     char *ptr;
  45.     extern int pclose();
  46.     extern FILE *fopen(), *popen();
  47.  
  48.     *name = '\0';
  49.  
  50.     /* try /etc/whoami */
  51.     if ((whoami = fopen("/etc/whoami", "r")) != 0) {
  52.         (void) fgets(name, len, whoami);
  53.         (void) fclose(whoami);
  54.         if ((ptr = index(name, '\n')) != 0)
  55.             *ptr = '\0';
  56.     }
  57.     if (*name)
  58.         return 0;
  59.  
  60.     /* try /usr/include/whoami.h */
  61.     if ((whoami = fopen("/usr/include/whoami.h", "r")) != 0) {
  62.         while (!feof(whoami)) {
  63.             char    buf[100];
  64.  
  65.             if (fgets(buf, 100, whoami) == 0)
  66.                 break;
  67.             if (sscanf(buf, "#define sysname \"%[^\"]\"", name))
  68.                 break;
  69.         }
  70.         (void) fclose(whoami);
  71.         if (*name)
  72.             return 0;
  73.     }
  74.  
  75.     /* ask uucp */
  76.     if ((whoami = popen("uuname -l", "r")) != 0) {
  77.         (void) fgets(name, len, whoami);
  78.         (void) pclose(whoami);
  79.         if ((ptr = index(name, '\n')) != 0)
  80.             *ptr = '\0';
  81.     }
  82.     if (*name)
  83.         return 0;
  84.  
  85.     /* aw hell, i give up!  is this really unix? */
  86.     return -1;
  87. #else /* AMIGA */
  88.     extern char *FindConfig();
  89.  
  90.     char *ptr;
  91.  
  92.     if((ptr = FindConfig("NodeName")) != NULL)
  93.     {
  94.       if(strlen(ptr) < len)
  95.       {
  96.         strcpy(name, ptr);
  97.         return 0;
  98.       }
  99.         }
  100.     return -1; /* something failed.. */
  101. #endif AMIGA
  102. }
  103. #endif /* GETHOSTNAME */
  104. #endif /* UNAME */
  105.