|
Lines 134-140
main(int argc, char *argv[])
Link Here
|
| 134 |
|
134 |
|
| 135 |
/* Open the file. */ |
135 |
/* Open the file. */ |
| 136 |
if ((fp = fopen(acctfile, "r")) == NULL || fstat(fileno(fp), &sb)) |
136 |
if ((fp = fopen(acctfile, "r")) == NULL || fstat(fileno(fp), &sb)) |
| 137 |
err(1, "%s", acctfile); |
137 |
err(1, "could not open %s", acctfile); |
| 138 |
|
138 |
|
| 139 |
/* |
139 |
/* |
| 140 |
* Round off to integral number of accounting records, probably |
140 |
* Round off to integral number of accounting records, probably |
|
Lines 146-162
main(int argc, char *argv[])
Link Here
|
| 146 |
if ((unsigned)size < sizeof(struct acct)) |
146 |
if ((unsigned)size < sizeof(struct acct)) |
| 147 |
exit(0); |
147 |
exit(0); |
| 148 |
|
148 |
|
| 149 |
/* |
149 |
do { |
| 150 |
* Seek to before the last entry in the file; use lseek(2) in case |
150 |
int rv; |
| 151 |
* the file is bigger than a "long". |
151 |
size -= sizeof(struct acct); |
| 152 |
*/ |
152 |
if (fseeko(fp, size, SEEK_SET) == -1) |
| 153 |
size -= sizeof(struct acct); |
153 |
err(1, "seek %s failed", acctfile); |
| 154 |
if (lseek(fileno(fp), size, SEEK_SET) == -1) |
154 |
if ((rv = fread(&ab, sizeof(struct acct), 1, fp)) != 1) |
| 155 |
err(1, "%s", acctfile); |
155 |
err(1, "read %s returned %d", acctfile, rv); |
| 156 |
|
|
|
| 157 |
for (;;) { |
| 158 |
if (fread(&ab, sizeof(struct acct), 1, fp) != 1) |
| 159 |
err(1, "%s", acctfile); |
| 160 |
|
156 |
|
| 161 |
if (ab.ac_comm[0] == '\0') { |
157 |
if (ab.ac_comm[0] == '\0') { |
| 162 |
ab.ac_comm[0] = '?'; |
158 |
ab.ac_comm[0] = '?'; |
|
Lines 211-222
main(int argc, char *argv[])
Link Here
|
| 211 |
} |
207 |
} |
| 212 |
printf("\n"); |
208 |
printf("\n"); |
| 213 |
|
209 |
|
| 214 |
if (size == 0) |
210 |
} while (size > 0); |
| 215 |
break; |
|
|
| 216 |
size -= sizeof(struct acct); |
| 217 |
if (fseek(fp, 2 * -(long)sizeof(struct acct), SEEK_CUR) == -1) |
| 218 |
err(1, "%s", acctfile); |
| 219 |
} |
| 220 |
exit(0); |
211 |
exit(0); |
| 221 |
} |
212 |
} |