static char *sccsid
= "@(#)last.c 4.3 (Berkeley) %G%";
#define NMAX sizeof(buf[0].ut_name)
#define LMAX sizeof(buf[0].ut_line)
#define SECDAY (24*60*60)
#define lineq(a,b) (!strncmp(a,b,LMAX))
#define nameq(a,b) (!strncmp(a,b,NMAX))
char ttnames
[MAXTTYS
][LMAX
+1];
char *ctime(), *strspl();
register struct utmp
*bp
;
char * crmsg
= (char *)0;
for (i
= 0; i
< argc
; i
++) {
if (!strcmp(argv
[i
], "~"))
argv
[i
] = strspl("tty", argv
[i
]);
wtmp
= open("/usr/adm/wtmp", 0);
bl
= (stb
.st_size
+ sizeof (buf
)-1) / sizeof (buf
);
if (signal(SIGINT
, SIG_IGN
) != SIG_IGN
) {
for (bl
--; bl
>= 0; bl
--) {
lseek(wtmp
, bl
* sizeof (buf
), 0);
bp
= &buf
[read(wtmp
, buf
, sizeof (buf
)) / sizeof(buf
[0]) - 1];
for ( ; bp
>= buf
; bp
--) {
ct
= ctime(&bp
->ut_time
);
printf("%-*.*s %-*.*s %10.10s %5.5s ",
LMAX
, LMAX
, bp
->ut_line
, ct
, 11+ct
);
for (i
= 0; i
< MAXTTYS
; i
++) {
if (ttnames
[i
][0] == 0) {
strncpy(ttnames
[i
], bp
->ut_line
,
logouts
[i
] = bp
->ut_time
;
if (lineq(ttnames
[i
], bp
->ut_line
)) {
logouts
[i
] = bp
->ut_time
;
printf(" still logged in\n");
delta
= otime
- bp
->ut_time
;
asctime(gmtime(&delta
))+11);
asctime(gmtime(&delta
))+11);
if (lineq(bp
->ut_line
, "~")) {
for (i
= 0; i
< MAXTTYS
; i
++)
logouts
[i
] = -bp
->ut_time
;
if (nameq(bp
->ut_name
, "shutdown"))
ct
= ctime(&buf
[0].ut_time
);
printf("\nwtmp begins %10.10s %5.5s \n", ct
, ct
+ 11);
ct
= ctime(&buf
[0].ut_time
);
printf("\ninterrupted %10.10s %5.5s \n", ct
, ct
+ 11);
if (bp
->ut_line
[0] == '~' && bp
->ut_name
[0] == '\0')
strcpy(bp
->ut_name
, "reboot"); /* bandaid */
for (ac
= 0; ac
< argc
; ac
++) {
if (nameq(*av
, bp
->ut_name
) || lineq(*av
, bp
->ut_line
))
char *res
= (char *)malloc(strlen(left
)+strlen(right
)+1);