Diff is not really meant for comparing binary files. I had a similar
problem a while back where I had to make sure that mkifs images were byte
for byte identical (mkifs includes some timestamp information normally). If
the files you’re comparing are the same size and you just want to see if
bytes differ at certain locations, you could use the ‘bindiff’ program I
wrote. It’s very naive and only compares bytes in the same position without
attempting to deal with insertions and deletions but it might help.
cheers,
Kris
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define BUFSIZE 1024
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)<(b))?(b):(a))
/* compare bytes returning 0 if there are no differences */
int
compare(char *buf1, char *buf2, int length, int offset)
{
static int diffcount = -1;
int i, retval = 0;
if(diffcount == -1)
diffcount = buf1[0] != buf2[0];
for(i = 0; i < length ; i++){
if(buf1 == buf2){
if(diffcount){
if(diffcount > 1)
printf(“to byte:0x%X\n”, offset + i);
else
printf("\n");
}
diffcount = 0;
}
else{
retval = 1;
if(!diffcount){
printf(“different at byte:0x%X “, offset + i);
}
diffcount++;
}
}
return retval;
}
int
main(int argc, char *argv[])
{
FILE *f1, f2;
int res1, res2, byte_count = 0, retval = 0;
char c1[BUFSIZE], c2[BUFSIZE];
if(argc != 3){
fprintf(stderr, “Usage: bindiff \n”);
exit(1);
}
if( !(f1 = fopen(argv[1], “r”)) ){
fprintf(stderr, “unable to open %s\n”, argv[1]);
exit(1);
}
if( !(f2 = fopen(argv[2], “r”)) ){
fclose(f1);
fprintf(stderr, “unable to open %s\n”, argv[2]);
exit(1);
}
while(1){
res1 = fread(c1, 1, BUFSIZE, f1);
res2 = fread(c2, 1, BUFSIZE, f2);
/ once retval is set, it stays set */
if(compare(c1, c2, MIN(res1, res2), byte_count) || retval)
retval = 1;
byte_count += MIN(res1, res2);
if(res1 != res2){
printf(”%s ends at byte 0x%X\n”, MIN(res1, res2) == res1 ? argv[1] :
argv[2], byte_count);
retval = 1;
break;
}
if(res1 < BUFSIZE)
break;
}
fclose(f1);
fclose(f2);
exit(retval);
}
“ed1k” <ed1k@yahoo.com> wrote in message
news:01c19aab$93b544a0$106fa8c0@ED1K…
_Hello,
I’d like to know is any PR on diff utility. Maybe I’ve done something
wrong, but here’s situation:
In order to compare mp3 streams which were generated by different builds
of encoder I used diff
utility
diff qnx.mp3 win.mp3
Those mp3’s were created from the same wav file and were about 3.5 Mb
large. The result was as
follow my console splashed and I lost the console - I’ve seen deep black
screen. Since I worked on
second console, I freely switched to another one (ctrl+alt+1|2|3|4 worked
perfectly, but after
ctrl+alt+2 I saw black screen), login and issue pidin - nothing odd.
What’s happens? Am I wrong in
diff usage? I tried
diff -n qnx.mp3 win.mp3
result was the same.
After reboot in windows I found there are few different bytes in mp3’s.
BTW, nothing abnormal when
I type
fc /b qnx.mp3 win.mp3
in windows. What’s wrong? How to compare binary files in QNX?
Thank you in advance,
Eduard._