* DESCRIPTION: Displays login history of named users or tty's.
* Last with no argument prints history for all users.
* AUTHOR - Howard P. Katseff
struct utmp buf
[128]; /* buf takes exactly 5 blocks */
for (i
= 1; i
< argc
; i
++)
length (argv
[i
]) > 2 /* long tty or user name */
equal (argv
[i
], "~") /* tilde */
getpwnam (argv
[i
]) /* user name */
move (argv
[i
], Arg
[narg
++]);
else /* short tty name */
move (argv
[i
], move ("tty", Arg
[narg
++]));
if (fstat (f
, &sbuf
) < 0)
perror ("/usr/adm/wtmp");
nblock
= (sbuf
.st_size
+ 2559) / 2560;
for (bl
= nblock
- 1; bl
>= 0; bl
--)
n_byte
= read (f
, buf
, 2560);
n_record
= n_byte
/ sizeof buf
[0];
for (rec
= n_record
- 1; rec
>= 0; rec
--)
q
= ctime (&buf
[rec
].ut_time
);
"%-8.8s %-8.8s %10.10s %5.5s ",
buf
[rec
].ut_name
, buf
[rec
].ut_line
, q
, 11+q
otime
= buf
[rec
].ut_time
;
* look up the logout time for the tty
/* not in the table, therefore add it */
printf (" still logged in\n");
printf ("- %5.5s", ctime (&ntime
) + 11);
* calculate how long logged in
otime
+= 231220830 + 10800;
if (otime
< 231220830 + 86400 + 10800)
(231330830-86400-10800))/86400,
equal (buf
[rec
].ut_line
, "~")
equal (buf
[rec
].ut_line
, "tty~")
for (i
= 0; *tty_names
[i
]; i
++)
logouts
[i
] = -buf
[rec
].ut_time
;
logouts
[k
] = buf
[rec
].ut_time
;
if (equal (tty_names
[k
], buf
[rec
].ut_line
))
logouts
[k
] = buf
[rec
].ut_time
;
q
= ctime (&buf
[0].ut_time
);
"\nwtmp begins %10.10s %5.5s \n",
if (*a
++ != *b
++) return (0);
signal (2, 1); /* ignore further interrupts */
q
= ctime (&buf
[rec
].ut_time
);
"\ninterrupted %10.10s %5.5s \n",
if (buf
[rec
].ut_name
[0] == no
) return no
; /* a logout entry */
if (!**Arg
) return yes
; /* no arguments? Print all login entries */
for (i
= 0; i
< *Arg
[i
]; i
++)
equal (Arg
[i
], buf
[rec
].ut_name
)
equal (Arg
[i
], buf
[rec
].ut_line
)