chiark / gitweb /
Merge branch 'master' into merge-141006
authorJonathan Amery <jdamery+zgit@ysolde.ucam.org>
Mon, 6 Oct 2014 11:59:10 +0000 (12:59 +0100)
committerJonathan Amery <jdamery+zgit@ysolde.ucam.org>
Mon, 6 Oct 2014 11:59:10 +0000 (12:59 +0100)
Conflicts:
acctdump.c

1  2 
cprogs/acctdump.c

index e1b76746efa514255b95dbe30c38f8b0a6a5c010,fbf7eadf24b980a619edbd4c3d2667bd077a2625..98fab9c55d4f96d0d782500894c99a5c1f62b4d1
@@@ -270,7 -275,8 +280,8 @@@ static void printrecord(const struct_ac
  }
  
  static void processfile(FILE *file, const char *filename) {
 -  struct acct as;
 +  struct_acct as;
+   long pos;
    int r;
    
    if (forwards) {
        printrecord(&as,filename);
      }
    } else {
 +    long seekdist= -(long)sizeof(as);
      r= fseek(file,0,SEEK_END); if (r) { perror(filename); exit(8); }
+     pos= ftell(file); if (pos==-1) { perror(filename); exit(8); }
+     if (pos % sizeof(as)) { 
+       fprintf(stderr, "%s: File size is not an integral number "
+             "of accounting records", filename);
+       exit(8);
+     }
      for (;;) {
-       r= fseek(file,seekdist,SEEK_CUR);
-       if (r) {
-       if (errno=EINVAL) break;
-       perror(filename); exit(8);
-       }
-       r= fread(&as,1,sizeof(as),file);
-       if (r!=sizeof(as)) { perror(filename); exit(8); }
+       if (pos<sizeof(as)) break;
+       pos -= sizeof(as);
+       r= fseek(file,pos,SEEK_SET); if (r==-1) { perror(filename); exit(8); }
+       r= fread(&as,1,sizeof(as),file); if (r!=sizeof(as)) { perror(filename); exit(8); }
        printrecord(&as,filename);
 +      seekdist= -2*(long)sizeof(as);
      }
    }
    if (ferror(file) || fclose(file)) { perror(filename); exit(8); }