Added lance entry to drivers.conf.
[minix3-old.git] / commands / simple / who.c
blob0989bd29c40cc527b8469d24a469816bb6e002fd
1 /* who 1.5 - tell who is currently logged in Author: Kees J. Bot
2 * 9 Jul 1989
3 */
4 #define nil 0
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <sys/stat.h>
10 #include <utmp.h>
11 #include <time.h>
12 #include <string.h>
13 #include <minix/paths.h>
15 char PATH_UTMP[] = _PATH_UTMP;
17 char day[] = "SunMonTueWedThuFriSat";
18 char month[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
20 int main(int argc, char **argv)
22 char *tmp= PATH_UTMP;
23 FILE *f;
24 struct utmp ut;
25 struct tm *tm;
26 int slot, wtmp= 0, once= 0;
28 if (argc > 3) {
29 fprintf(stderr, "Usage: who <account-file> | who am i\n");
30 exit(1);
32 if (argc == 2) {
33 tmp= argv[1];
34 wtmp= 1;
37 if ((f= fopen(tmp, "r")) == nil) {
38 fprintf(stderr, "who: can't open %s\n", tmp);
39 exit(1);
41 if (argc == 3) {
42 if ((slot= ttyslot()) < 0) {
43 fprintf(stderr, "who: no access to terminal.\n");
44 exit(1);
46 fseek(f, (off_t) sizeof(ut) * slot, 0);
47 once= 1;
50 while (fread((char *) &ut, sizeof(ut), 1, f) == 1) {
51 if (!wtmp && ut.ut_name[0] == 0) continue;
53 tm= localtime(&ut.ut_time);
55 printf("%-9.8s %-9.8s %.3s %.3s %2d %02d:%02d",
56 ut.ut_name,
57 ut.ut_line,
58 day + (3 * tm->tm_wday),
59 month + (3 * tm->tm_mon),
60 tm->tm_mday,
61 tm->tm_hour,
62 tm->tm_min
65 if (ut.ut_host[0] != 0) printf(" (%.*s)",
66 (int) sizeof(ut.ut_host), ut.ut_host);
68 printf("\n");
69 if (once) break;
71 exit(0);