home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / shar-3.49 / who@where.c < prev   
Encoding:
C/C++ Source or Header  |  1995-05-03  |  3.2 KB  |  116 lines

  1. /* $Header: /u/rhg/src/shar/who@where.c,v 3.49 90/09/12 15:15:33 rhg Exp $ */
  2.  
  3. /*+-------------------------------------------------------------------------
  4.     who@where.c - find out who i am & where i am
  5.     ...!gatech!kd4nc!n4hgf!wht (wht%n4hgf@gatech.edu)
  6. --------------------------------------------------------------------------*/
  7. /*+:EDITS:*/
  8. /*:09-12-1990-01:04-rhg@cps.com-added declarations of strcpy and strcat */
  9. /*:09-09-1990-19:49-rhg@cps.com-added explicit return statement to who_where */
  10. /*:04-03-1990-19:55-wht@n4hgf-get rid of complicated who_am_i */
  11. /*:04-01-1990-13:30-pat@rwing-use utsname.nodename instead of sysname */
  12. /*:04-02-1990-12:12-wht@n4hgf-sigh... some pwd.h dont declare functions */
  13. /*:03-29-1990-18:23-wht@n4hgf-add automatic sequent support */
  14. /*:03-28-1990-15:24-wht@n4hgf-creation */
  15.  
  16. #include <stdio.h>
  17. #include <sys/types.h>
  18. #include <pwd.h>
  19.  
  20. /* assume system v unless otherwise fixed */
  21. #if (defined(pyr) || defined(vax) || defined(sequent)) && !defined(BSD42) && !defined(SYS5)
  22. #define BSD42
  23. #endif
  24. #if defined(sun)    /* this miscreant doesn't exactly fit BSD or SYSV */
  25. #undef BSD42
  26. #undef SYS5
  27. #endif
  28. #if !defined(BSD42) && !defined(sun) && !defined(SYS5)
  29. #define SYS5
  30. #endif
  31.  
  32. #if defined(sun) || defined(BSD42)
  33. #define strchr    index
  34. #define strrchr    rindex
  35. #endif
  36.  
  37. #if !defined(SYS5) || defined(sun)
  38. #include <sys/time.h>
  39. extern int errno;
  40. #else
  41. #include <sys/utsname.h>
  42. #include <time.h>
  43. #endif    /* system dependencies */
  44.  
  45. char *strcpy();
  46. char *strcat();
  47. struct passwd *getpwuid();
  48.  
  49. /*+-------------------------------------------------------------------------
  50.     who_am_i() - get user name
  51. --------------------------------------------------------------------------*/
  52. char *
  53. who_am_i()
  54. {
  55.     struct passwd *passwd;
  56.     passwd = getpwuid(getuid());
  57.     (void)endpwent();
  58.     if(passwd == (struct passwd *)0)
  59.         return("???");
  60.     return(passwd->pw_name);
  61.  
  62. }    /* end of who_am_i */
  63.  
  64. /*+-------------------------------------------------------------------------
  65.     where_am_i() - do uname, gethostname, or read file (/etc/systemid)
  66. --------------------------------------------------------------------------*/
  67. char *
  68. where_am_i()
  69. {
  70. #if defined(M_UNIX) && defined(M_XENIX) /* SCO UNIX */
  71. static char where_i_am[64];
  72.     gethostname(where_i_am,sizeof(where_i_am));
  73.     return(where_i_am);
  74. #else /* M_UNIX && M_XENIX */
  75. #if defined(M_SYS5)    /* SCO XENIX */
  76. FILE *fpsid = fopen("/etc/systemid","r");
  77. static char s20[20];
  78.     if(!fpsid)
  79.         return("???");
  80.     fgets(s20,sizeof(s20),fpsid);
  81.     fclose(fpsid);
  82.     s20[strlen(s20) - 1] = 0;
  83.     return(s20);
  84. #else /* M_SYS5 */
  85. #if defined(SYS5)
  86. static struct utsname where_i_am;
  87.     uname(&where_i_am);
  88.     return(where_i_am.nodename);
  89. #else /* SYS5 */
  90. static char where_i_am[64];
  91.     gethostname(where_i_am,sizeof(where_i_am));
  92.     return(where_i_am);
  93. #endif /* SYS5 */
  94. #endif /* M_SYS5 */
  95. #endif /* M_UNIX && M_XENIX */
  96. }    /* end of where_am_i */
  97.  
  98. /*+-------------------------------------------------------------------------
  99.     who_where(buf)
  100. --------------------------------------------------------------------------*/
  101. char *
  102. who_where(buf)
  103. char *buf;
  104. {
  105. static char ww[64];
  106.  
  107.     if(!buf)
  108.         buf = ww;
  109.     strcpy(buf,who_am_i());
  110.     strcat(buf,"@");
  111.     return(strcat(buf,where_am_i()));
  112. }    /* end of who_where */
  113.  
  114. /* vi: set tabstop=4 shiftwidth=4: */
  115. /* end of who@where.c */
  116.