home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / mint / init_5 / who.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-03  |  1.3 KB  |  94 lines

  1. /*
  2.  * Who.c  A re-implementation of the BSD who(1) command.
  3.  *
  4.  *    Version 1.0 (c) S.R.Usher 1991.
  5.  *
  6.  * Changelog
  7.  *
  8.  * 20/10/91    S.R.Usher    1.0    First version.
  9.  *
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <fcntl.h>
  14. #include <sys/time.h>
  15. #include <utmp.h>
  16.  
  17. #define UTMP_FILE "/etc/utmp"
  18.  
  19. main()
  20. {
  21.     int fd;
  22.     struct utmp entry;
  23.  
  24.     if ((fd = open(UTMP_FILE, O_RDONLY)) == -1)
  25.     {
  26.         perror(UTMP_FILE);
  27.         exit(0);
  28.     }
  29.  
  30.     while (read(fd, &entry, sizeof(struct utmp)) == sizeof(struct utmp))
  31.     {
  32.         if (!nonuser(entry))
  33.         {
  34.             if (entry.ut_name[0] != '\0')
  35.             {
  36.                 print_entry(&entry);
  37.             }
  38.         }
  39.     }
  40.  
  41.     close(fd);
  42.     exit(0);
  43. }
  44.  
  45. print_entry(entry)
  46. struct utmp *entry;
  47. {
  48.     char *fmt;
  49.     char output[80];
  50.     struct tm *this_time;
  51.  
  52.     static char *dow[7] = {
  53.         "Sun",
  54.         "Mon",
  55.         "Tue",
  56.         "Wed",
  57.         "Thu",
  58.         "Fri",
  59.         "Sat"
  60.     };
  61.  
  62.     static char *moy[12] = {
  63.         "Jan",
  64.         "Feb",
  65.         "Mar",
  66.         "Apr",
  67.         "May",
  68.         "Jun",
  69.         "Jul",
  70.         "Aug",
  71.         "Sep",
  72.         "Oct",
  73.         "Nov",
  74.         "Dec"
  75.     };
  76.  
  77.  
  78.     if (entry->ut_host[0] != '\0')
  79.         fmt = "%-8s %-8s %s %s %2d %2d:%02d:%02d (%s)\n";
  80.     else
  81.         fmt = "%-8s %-8s %s %s %2d %2d:%02d:%02d\n";
  82.  
  83.     this_time = localtime(&(entry->ut_time));
  84.  
  85.     printf(fmt, entry->ut_name, entry->ut_line,
  86.             dow[this_time->tm_wday],
  87.             moy[this_time->tm_mon],
  88.             this_time->tm_mday,
  89.             this_time->tm_hour,
  90.             this_time->tm_min,
  91.             this_time->tm_sec,
  92.             entry->ut_host);
  93. }
  94.