|
|
1.1 ! root 1: /* ! 2: * Rec'd from Lauren, 7-16-84. ! 3: * Who is on the system ! 4: * and who am i. ! 5: */ ! 6: ! 7: #include <stdio.h> ! 8: #include <utmp.h> ! 9: ! 10: char *whofile = "/etc/utmp"; ! 11: int ordflag = 1; /* Ordinary who */ ! 12: ! 13: char obuf[BUFSIZ]; ! 14: ! 15: main(argc, argv) ! 16: char *argv[]; ! 17: { ! 18: register char *mytty = NULL; ! 19: struct utmp utmp; ! 20: register FILE *ufp; ! 21: extern char *ttyname(); ! 22: extern char *ctime(); ! 23: ! 24: setbuf(stdout, obuf); ! 25: switch(argc) { ! 26: case 1: /* who */ ! 27: break; ! 28: case 2: /* who whofile */ ! 29: whofile = argv[1]; ! 30: ordflag = 0; ! 31: break; ! 32: case 3: /* who am i */ ! 33: if ((mytty = ttyname(fileno(stderr))) != NULL) ! 34: mytty += 5; /* space over "/dev" */ ! 35: break; ! 36: case 4: /* who whofile am i */ ! 37: whofile = argv[1]; ! 38: ordflag = 0; ! 39: if ((mytty = ttyname(fileno(stderr))) != NULL) ! 40: mytty += 5; /* space over "/dev" */ ! 41: break; ! 42: default: ! 43: usage(); ! 44: } ! 45: if ((ufp = fopen(whofile, "r")) == NULL) ! 46: werr("Cannot open %s\n", whofile); ! 47: while (fread(&utmp, sizeof (utmp), 1, ufp) == 1) { ! 48: if (ordflag && utmp.ut_name[0]=='\0') ! 49: continue; ! 50: if (mytty!=NULL && strncmp(utmp.ut_line, mytty, 8)) ! 51: continue; ! 52: printf( "%-8.8s %-7.7s %.12s\n", utmp.ut_name, utmp.ut_line, ! 53: ctime( &utmp.ut_time)+4); ! 54: } ! 55: } ! 56: ! 57: /* VARARGS */ ! 58: werr(x) ! 59: { ! 60: if (!isatty(fileno(stdout))) ! 61: fprintf(stderr, "who: "); ! 62: fprintf(stderr, "%r", &x); ! 63: exit (1); ! 64: } ! 65: ! 66: usage() ! 67: { ! 68: werr("Usage: who [who-file] [am I]\n"); ! 69: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.