1: /*
   2:  * users
   3:  */
   4: char    *malloc();
   5: 
   6: #include <stdio.h>
   7: #include <utmp.h>
   8: 
   9: #define NMAX sizeof(utmp.ut_name)
  10: #define LMAX sizeof(utmp.ut_line)
  11: 
  12: struct utmp utmp;
  13: 
  14: main(argc, argv)
  15: char **argv;
  16: {
  17:     register char *tp, *s;
  18:     register FILE *fi;
  19: 
  20:     s = "/etc/utmp";
  21:     if(argc == 2)
  22:         s = argv[1];
  23:     if ((fi = fopen(s, "r")) == NULL) {
  24:         puts("who: cannot open utmp");
  25:         exit(1);
  26:     }
  27:     while (fread((char *)&utmp, sizeof(utmp), 1, fi) == 1) {
  28:         if(utmp.ut_name[0] == '\0')
  29:             continue;
  30:         putline();
  31:     }
  32:     summary();
  33: }
  34: 
  35: char    *names[128];
  36: char    **namp = names;
  37: putline()
  38: {
  39:     char temp[NMAX+1];
  40:     strncpy(temp, utmp.ut_name, NMAX);
  41:     temp[NMAX] = 0;
  42:     *namp = malloc(strlen(temp) + 1);
  43:     strcpy(*namp++, temp);
  44: }
  45: 
  46: scmp(p, q)
  47: char **p, **q;
  48: {
  49:     return(strcmp(*p, *q));
  50: }
  51: summary()
  52: {
  53:     register char **p;
  54: 
  55:     qsort(names, namp - names, sizeof names[0], scmp);
  56:     for (p=names; p < namp; p++) {
  57:         if (p != names)
  58:             printf(" ");
  59:         printf("%s", *p);
  60:     }
  61:     printf("\n");
  62: }

Defined functions

main defined in line 14; never used
putline defined in line 37; used 1 times
  • in line 30
scmp defined in line 46; used 1 times
  • in line 55
summary defined in line 51; used 1 times
  • in line 32

Defined variables

names defined in line 35; used 6 times
namp defined in line 36; used 4 times
utmp defined in line 12; used 6 times

Defined macros

LMAX defined in line 10; never used
NMAX defined in line 9; used 3 times
Last modified: 1980-08-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 795
Valid CSS Valid XHTML 1.0 Strict