diff options
author | hmp <hmp@FreeBSD.org> | 2004-05-20 19:25:27 +0000 |
---|---|---|
committer | hmp <hmp@FreeBSD.org> | 2004-05-20 19:25:27 +0000 |
commit | 2b45c8c6e0e67625cc5fb5845592d20bed18edf8 (patch) | |
tree | b85ac07f30add4caaaeb678a2058c20ce848e25e /usr.bin/lastcomm | |
parent | 96189f4c1fca37543e83dd2296f1b328ed5a33e9 (diff) | |
download | FreeBSD-src-2b45c8c6e0e67625cc5fb5845592d20bed18edf8.zip FreeBSD-src-2b45c8c6e0e67625cc5fb5845592d20bed18edf8.tar.gz |
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>
Diffstat (limited to 'usr.bin/lastcomm')
-rw-r--r-- | usr.bin/lastcomm/lastcomm.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/usr.bin/lastcomm/lastcomm.c b/usr.bin/lastcomm/lastcomm.c index ab67a2c..377de60 100644 --- a/usr.bin/lastcomm/lastcomm.c +++ b/usr.bin/lastcomm/lastcomm.c @@ -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); } |