1 /* who 1.5 - tell who is currently logged in Author: Kees J. Bot
15 char PATH_UTMP
[] = _PATH_UTMP
;
17 char day
[] = "SunMonTueWedThuFriSat";
18 char month
[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
20 int main(int argc
, char **argv
)
26 int slot
, wtmp
= 0, once
= 0;
29 fprintf(stderr
, "Usage: who <account-file> | who am i\n");
37 if ((f
= fopen(tmp
, "r")) == nil
) {
38 fprintf(stderr
, "who: can't open %s\n", tmp
);
42 if ((slot
= ttyslot()) < 0) {
43 fprintf(stderr
, "who: no access to terminal.\n");
46 fseek(f
, (off_t
) sizeof(ut
) * slot
, 0);
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",
58 day
+ (3 * tm
->tm_wday
),
59 month
+ (3 * tm
->tm_mon
),
65 if (ut
.ut_host
[0] != 0) printf(" (%.*s)",
66 (int) sizeof(ut
.ut_host
), ut
.ut_host
);