1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: char copyright[] =
   9: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  10:  All rights reserved.\n";
  11: #endif not lint
  12: 
  13: #ifndef lint
  14: static char sccsid[] = "@(#)users.c	5.2 (Berkeley) 11/15/85";
  15: #endif not lint
  16: 
  17: /*
  18:  * users
  19:  */
  20: char    *malloc();
  21: 
  22: #include <stdio.h>
  23: #include <utmp.h>
  24: 
  25: #define NMAX sizeof(utmp.ut_name)
  26: #define LMAX sizeof(utmp.ut_line)
  27: 
  28: struct utmp utmp;
  29: 
  30: main(argc, argv)
  31: char **argv;
  32: {
  33:     register char *tp, *s;
  34:     register FILE *fi;
  35: 
  36:     s = "/etc/utmp";
  37:     if(argc == 2)
  38:         s = argv[1];
  39:     if ((fi = fopen(s, "r")) == NULL) {
  40:         perror(s);
  41:         exit(1);
  42:     }
  43:     while (fread((char *)&utmp, sizeof(utmp), 1, fi) == 1) {
  44:         if(utmp.ut_name[0] == '\0')
  45:             continue;
  46:         putline();
  47:     }
  48:     summary();
  49: }
  50: 
  51: char    *names[128];
  52: char    **namp = names;
  53: putline()
  54: {
  55:     char temp[NMAX+1];
  56:     strncpy(temp, utmp.ut_name, NMAX);
  57:     temp[NMAX] = 0;
  58:     *namp = malloc(strlen(temp) + 1);
  59:     strcpy(*namp++, temp);
  60: }
  61: 
  62: scmp(p, q)
  63: char **p, **q;
  64: {
  65:     return(strcmp(*p, *q));
  66: }
  67: summary()
  68: {
  69:     register char **p;
  70: 
  71:     qsort(names, namp - names, sizeof names[0], scmp);
  72:     for (p=names; p < namp; p++) {
  73:         if (p != names)
  74:             putchar(' ');
  75:         fputs(*p, stdout);
  76:     }
  77:     if (namp != names)      /* at least one user */
  78:         putchar('\n');
  79: }

Defined functions

main defined in line 30; never used
putline defined in line 53; used 1 times
  • in line 46
scmp defined in line 62; used 1 times
  • in line 71
summary defined in line 67; used 1 times
  • in line 48

Defined variables

copyright defined in line 8; never used
names defined in line 51; used 7 times
namp defined in line 52; used 5 times
sccsid defined in line 14; never used
utmp defined in line 28; used 6 times

Defined macros

LMAX defined in line 26; never used
NMAX defined in line 25; used 3 times
Last modified: 1986-01-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 683
Valid CSS Valid XHTML 1.0 Strict