Fixed bug about file content comparison.
This commit is contained in:
parent
9e2e5817e6
commit
2f28ad5c65
@ -118,7 +118,7 @@ int Compare_2_files(char *adr1, char *adr2, char *adrc, int flag)
|
||||
printf("- %s : cannot open() : %s\n", adr1, strerror(errno));
|
||||
return(0);
|
||||
}
|
||||
fd2= open(adr1, O_RDONLY);
|
||||
fd2= open(adr2, O_RDONLY);
|
||||
if(fd2==-1) {
|
||||
printf("- %s : cannot open() : %s\n", adr2, strerror(errno));
|
||||
close(fd1);
|
||||
@ -132,17 +132,24 @@ int Compare_2_files(char *adr1, char *adr2, char *adrc, int flag)
|
||||
if((r1==EOF && r2==EOF) || (r1==0 && r2==0))
|
||||
break;
|
||||
if(r1==EOF || r1==0) {
|
||||
if(r1==EOF)
|
||||
r1= 0;
|
||||
if(s1.st_size > r1count + r1)
|
||||
printf("- %s : early EOF after %d bytes\n", adr1, r1count);
|
||||
differs= 1;
|
||||
break;
|
||||
}
|
||||
r1count+= r1;
|
||||
if(r2==EOF || r2<r1) {
|
||||
if(r2==EOF)
|
||||
r2= 0;
|
||||
if(s2.st_size > r2count + r2)
|
||||
printf("- %s : early EOF after %d bytes\n", adr2, r2count);
|
||||
differs= 1;
|
||||
break;
|
||||
}
|
||||
if(r2>r1) {
|
||||
if(s1.st_size > r1count + r1)
|
||||
printf("- %s : early EOF after %d bytes\n", adr1, r1count);
|
||||
differs= 1;
|
||||
break;
|
||||
@ -157,8 +164,9 @@ int Compare_2_files(char *adr1, char *adr2, char *adrc, int flag)
|
||||
}
|
||||
}
|
||||
if(diffcount>0) {
|
||||
printf("%s : Content differs by %.f bytes. First at %.f\n",
|
||||
a, (double) diffcount, (double) first_diff);
|
||||
printf("%s : %s : differs by at least %.f bytes. First at %.f\n",
|
||||
a, (s1.st_size==s2.st_size || s1.st_mtime==s2.st_mtime ?
|
||||
"CONTENT":"content"), (double) diffcount, (double) first_diff);
|
||||
differs= 1;
|
||||
}
|
||||
}
|
||||
@ -170,13 +178,21 @@ int Compare_2_files(char *adr1, char *adr2, char *adrc, int flag)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
int ret, i, with_ctime= 1;
|
||||
char adr1[4096], adr2[4096], adrc[4096];
|
||||
|
||||
if(argc<4) {
|
||||
fprintf(stderr, "usage: %s path prefix1 prefix2\n", argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
for(i= 4; i<argc; i++) {
|
||||
if(strcmp(argv[i], "-no_ctime")==0)
|
||||
with_ctime= 0;
|
||||
else {
|
||||
fprintf(stderr, "%s : Option not recognized: '%s'\n", argv[0], argv[i]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if(strncmp(argv[1], argv[2], strlen(argv[2]))!=0) {
|
||||
fprintf(stderr, "%s: path '%s' does not match prefix1 '%s'\n",
|
||||
@ -187,7 +203,7 @@ int main(int argc, char **argv)
|
||||
strcpy(adrc, argv[1]+strlen(argv[2]));
|
||||
sprintf(adr2, "%s%s%s", argv[3], (adrc[0]=='/' ? "" : "/"), adrc);
|
||||
|
||||
ret= Compare_2_files(adr1, adr2, adrc, 2);
|
||||
ret= Compare_2_files(adr1, adr2, adrc, (with_ctime<<1));
|
||||
exit(ret<=0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user