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