Remove unneeded lseek(2) hack to position past the 2GB point,
use fseeko(3) instead. This commit fixes breakage when `lastcomm matchstring` is run. PR: bin/66765, bin/64568 Submitted by: Dan Nelson <dnelson at allantgroup.com>
This commit is contained in:
parent
96189f4c1f
commit
2b45c8c6e0
@ -134,7 +134,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Open the file. */
|
||||
if ((fp = fopen(acctfile, "r")) == NULL || fstat(fileno(fp), &sb))
|
||||
err(1, "%s", acctfile);
|
||||
err(1, "could not open %s", acctfile);
|
||||
|
||||
/*
|
||||
* Round off to integral number of accounting records, probably
|
||||
@ -146,17 +146,13 @@ main(int argc, char *argv[])
|
||||
if ((unsigned)size < sizeof(struct acct))
|
||||
exit(0);
|
||||
|
||||
/*
|
||||
* Seek to before the last entry in the file; use lseek(2) in case
|
||||
* the file is bigger than a "long".
|
||||
*/
|
||||
size -= sizeof(struct acct);
|
||||
if (lseek(fileno(fp), size, SEEK_SET) == -1)
|
||||
err(1, "%s", acctfile);
|
||||
|
||||
for (;;) {
|
||||
if (fread(&ab, sizeof(struct acct), 1, fp) != 1)
|
||||
err(1, "%s", acctfile);
|
||||
do {
|
||||
int rv;
|
||||
size -= sizeof(struct acct);
|
||||
if (fseeko(fp, size, SEEK_SET) == -1)
|
||||
err(1, "seek %s failed", acctfile);
|
||||
if ((rv = fread(&ab, sizeof(struct acct), 1, fp)) != 1)
|
||||
err(1, "read %s returned %d", acctfile, rv);
|
||||
|
||||
if (ab.ac_comm[0] == '\0') {
|
||||
ab.ac_comm[0] = '?';
|
||||
@ -211,12 +207,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
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);
|
||||
}
|
||||
} while (size > 0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user