1: /*
   2:  * who
   3:  */
   4: 
   5: int fout;
   6: int buf[256];
   7: 
   8: main(argc, argv)
   9: char **argv;
  10: {
  11:     char *s, *cbuf;
  12:     int n, fi, i;
  13:     int tty;
  14:     struct {
  15:         char name[8];
  16:         char tty;
  17:         char pad1;
  18:         int time[2];
  19:         char pad2[2];
  20:     } *p;
  21: 
  22:     s = "/etc/utmp";
  23:     if(argc == 2)
  24:         s = argv[1];
  25:     fi = open(s, 0);
  26:     if(fi < 0) {
  27:         write("cannot open wtmp\n", 17);
  28:         exit();
  29:     }
  30:     fout = dup(1);
  31:     close(1);
  32:     if (argc==3)
  33:         tty = ttyn(0);
  34: 
  35: loop:
  36:     n = read(fi, buf, 512);
  37:     if(n == 0) {
  38:         flush();
  39:         if (argc==3)
  40:             write(fout, "Nobody.\n", 8);
  41:         exit();
  42:     }
  43: 
  44:     p = &buf;
  45:     for(p = &buf; (n =- 16)>=0; p++) {
  46:         if (argc==3 && tty!=p->tty)
  47:             continue;
  48:         if(p->name[0] == '\0' && argc==1)
  49:             continue;
  50:         for(i=0; i<8; i++) {
  51:             if(p->name[i] == '\0')
  52:                 p->name[i] = ' ';
  53:             putchar(p->name[i]);
  54:         }
  55:         for(i=0; i<3; i++)
  56:             putchar("tty"[i]);
  57:         putchar(p->tty);
  58:         cbuf = ctime(p->time);
  59:         for(i=3; i<16; i++)
  60:             putchar(cbuf[i]);
  61:         putchar('\n');
  62:         if (argc==3) {
  63:             flush();
  64:             exit();
  65:         }
  66:     }
  67:     goto loop;
  68: }

Defined functions

main defined in line 8; never used

Defined variables

buf defined in line 6; used 3 times
fout defined in line 5; used 2 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 606
Valid CSS Valid XHTML 1.0 Strict