/* Copyright (c) 1979 Regents of the University of California */
* DESCRIPTION: Displays login history of named users or tty's.
* Last with no argument prints history for all users.
* EXTERNAL ROUTINES USED: bread.c blseek.c
* AUTHOR - Howard P. Katseff
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");
for (;;) /* the large loop */
q
= ctime (&buf
.ut_time
);
"\nwtmp begins %10.10s %5.5s \n",
* read the next login-logout record
if (bread (f
, &buf
+1, -sizeof buf
) < sizeof buf
)
perror ("impossible error\n");
q
= ctime (&buf
.ut_time
);
"%-8.8s %-8.8s %10.10s %5.5s ",
buf
.ut_name
, buf
.ut_line
, q
, 11+q
* look up the logout time for the tty
{ /* not in the table, therefore add it */
move (buf
.ut_line
, tty_names
[i
]);
if (equal (tty_names
[i
], buf
.ut_line
))
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,
if (equal (buf
.ut_line
, "~"))
for (i
= 0; *tty_names
[i
]; i
++)
logouts
[i
] = -buf
.ut_time
;
move (buf
.ut_line
, tty_names
[i
]);
if (equal (tty_names
[i
], buf
.ut_line
))
logouts
[i
] = buf
.ut_time
;
if (*a
++ != *b
++) return (0);
signal (2, 1); /* ignore further interrupts */
q
= ctime (&buf
.ut_time
);
"\ninterrupted %10.10s %5.5s \n",
* bread (), brseek (), blseek ()
* This is a buffered read package which simulates
* read (), lseek () and lseek ().
* Bread may be called with a negative nbytes which causes it to
* read backwards. In this case, buffer should point to the first
* byte following the buffer. If only a partial read is possible
* (due to beginning of file), only the last bytes of the buffer
bread (file
, buff
, nbytes
)
for (nb
= nbytes
; nb
> 0; nb
--)
nr
= read (file
, next
=b
, 512);
if (nr
== 0) return (nbytes
- nb
);
for (nb
= nbytes
; nb
> 0; nb
--)
lseek (file
, (long) - (512 + nr
), 1);
nl
= read (file
, b
, 512);
for (k
= 511; k
> 0; k
--)
lseek (file
, (long) 1, 1);
if (nl
< 0) return (nbytes
-nb
);
if (nl
== 0) return (nbytes
-nb
);
brseek (file
, offset
, flag
)
return (lseek (file
, (long) offset
, flag
));
blseek (file
, offset
, flag
)
return (lseek (file
, offset
, flag
));
if (buf
.ut_name
[0] == no
) return no
; /* a logout entry */
for (i
= 0; i
< *Arg
[i
]; i
++)
equal (Arg
[i
], buf
.ut_name
)
equal (Arg
[i
], buf
.ut_line
)