* SYNOPSIS: last [-] [name ...]
* DESCRIPTION: Displays login history of named users or tty's.
* Last with no argument prints history for all users.
* Last - displays history for all non-class users.
* EXTERNAL ROUTINES USED: bread.c blseek.c
* AUTHOR - Howard P. Katseff
struct {char c1
, c2
, c3
, c4
;};
if (allflag
= argc
==1) argv
--;
f
= open("/usr/adm/wtmp", 0);
printf("Can't open /usr/adm/wtmp\n");
for (i
=0; i
<127; i
++) logouts
[i
] = 0;
if ((signal(2,1) && 01) == 0) {
f
= open("/usr/adm/owtmp", 0);
if (count
++ == 0 && f
> 0) goto x
;
printf("\nwtmp begins at %10.10s %5.5s \n",
if (bread(f
, buf
+16, -16) < 16) {
perror("impossible error");
for (p
= 1+argv
; *p
!= -1; p
++) {
printf("%8.8s tty%c %10.10s %5.5s ",
printf("%8.8s tty^%c %10.10s %5.5s ",
printf(" still logged in\n");
else printf("- %5.5s", 11+ctime(&ntime
));
for (i
=0; i
<127; i
++) logouts
[i
] = -(buf
+10)->l1
;
else logouts
[tty
] = (buf
+10)->l1
;
if (allflag
&& (*c2
!= '\0' || *(c2
+8) >= '|')) return(1);
if ((*c1
== '-') || (*c1
== 'x')) {
if (*c2
== '\0' && *(c2
+8) < '|') return(0);
if (*c2
>= '0' && *c2
<= '9') return(0);
if (*(c2
+2) >= '0' && *(c2
+2) <= '9') return(0);
for(i
=0; i
<8; i
++) if (*c2
++ == '-') return(0);
if (*c1
== *(c2
+8) && (*c1
>= '|' || *c2
!= '\0')) return(1);
if (*c1
== '\0') return(*c2
== ' ');
if (*c1
++ != *c2
++) return(0);
printf("\ninterrupted at %10.10s %5.5s \n",
printf("\ninterrupted at %10.10s %5.5s \n",
* NAMES: bread(), brseek(), blseek()
* This is a buffered read package which simulates read(), seek() and
* 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
--) {
seek(file
, -(512 + nr
), 1);
if (nl
< 0) return(nbytes
-nb
);
if (nl
== 0) return(nbytes
-nb
);
brseek(file
, offset
, flag
) {
return(seek(file
,offset
,flag
));
blseek(file
, offset
, flag
)
return(lseek(file
,offset
,flag
));