Don't try to fseek before the beginning of the file; POSIX requires that
this return an error. This re-enables display of the first entry in /var/account/acct instead of the error "lastcomm: /var/account/acct: Invalid argument"
This commit is contained in:
parent
58b8fa7412
commit
6841d8b90d
@ -60,6 +60,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include <utmp.h>
|
||||
#include "pathnames.h"
|
||||
|
||||
/*XXX*/#include <inttypes.h>
|
||||
|
||||
time_t expand(u_int);
|
||||
char *flagbits(int);
|
||||
const char *getdev(dev_t);
|
||||
@ -156,13 +158,6 @@ main(int argc, char *argv[])
|
||||
if (fread(&ab, sizeof(struct acct), 1, fp) != 1)
|
||||
err(1, "%s", acctfile);
|
||||
|
||||
if (fseek(fp, 2 * -(long)sizeof(struct acct), SEEK_CUR) == -1)
|
||||
err(1, "%s", acctfile);
|
||||
|
||||
if (size == 0)
|
||||
break;
|
||||
size -= sizeof(struct acct);
|
||||
|
||||
if (ab.ac_comm[0] == '\0') {
|
||||
ab.ac_comm[0] = '?';
|
||||
ab.ac_comm[1] = '\0';
|
||||
@ -215,6 +210,12 @@ main(int argc, char *argv[])
|
||||
(void)printf(" %.16s", ctime(&t));
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if (size == 0)
|
||||
break;
|
||||
size -= sizeof(struct acct);
|
||||
if (fseek(fp, 2 * -(long)sizeof(struct acct), SEEK_CUR) == -1)
|
||||
err(1, "%s", acctfile);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user