- while (read(f, (char *)&wtmp, sizeof(wtmp)) == sizeof(wtmp)) {
- if (SCMPN(wtmp.ut_line, p->line) || wtmp.ut_name[0]==0)
- continue;
- lseek(f, -(long)sizeof(wtmp), 1);
- SCPYN(wtmp.ut_name, "");
- SCPYN(wtmp.ut_host, "");
- time(&wtmp.ut_time);
- write(f, (char *)&wtmp, sizeof(wtmp));
- found++;
+ fstat(f, &statbf);
+ if (utmpsize < statbf.st_size) {
+ utmpsize = statbf.st_size + 10 * sizeof(struct utmp);
+ if (utmp)
+ utmp = (struct utmp *)realloc(utmp, utmpsize);
+ else
+ utmp = (struct utmp *)malloc(utmpsize);
+ if (!utmp)
+ syslog(LOG_ERR, "utmp malloc failed");
+ }
+ if (statbf.st_size && utmp) {
+ nutmp = read(f, utmp, statbf.st_size);
+ nutmp /= sizeof(struct utmp);
+ for (u = utmp ; u < &utmp[nutmp] ; u++) {
+ if (u->ut_name[0] == 0 ||
+ SCMPN(u->ut_line, p->line))
+ continue;
+ lseek(f, ((long)u)-((long)utmp), L_SET);
+ SCPYN(u->ut_name, "");
+ SCPYN(u->ut_host, "");
+ time(&u->ut_time);
+ write(f, (char *)u, sizeof(*u));
+ found++;
+ }