diff

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.

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._

I just thought of another solution that might work - uuencode the files and
then diff them. They’ll be text then and it might work a bit better. Just
a thought.

cheers,

Kris

“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.

Thank you Kris. I’ll use your program :wink: but I guess it’s temporary solution. Why there is no -b
option like it is in dos? It’s very odd IMO. dos’s fc /b does the same thing: byte to byte
comparison and print

: if bytes are differed. It's all. Simple as egg :wink: I suspected about the trap in diff. BTW, what about diff3? Thank you again, Best regards.

try /usr/bin/cmp

ed1k wrote:

Thank you Kris. I’ll use your program > :wink: > but I guess it’s temporary solution. Why there is no -b
option like it is in dos? It’s very odd IMO. dos’s fc /b does the same thing: byte to byte
comparison and print
address>: <byte in first file (hex)> <byte in second file (hex)
if bytes are differed. It’s all. Simple as egg > :wink:
I suspected about the trap in diff. BTW, what about diff3?
Thank you again,
Best regards.

Thanks GUI Group,
I’ll try it if i have it. Where does it come from? I did not find it in helpviewer last night, I
will more careful this night :wink:
Eduard.

GUI Group <gui@qnx.com> wrote in article <3C3F0E2D.7030707@qnx.com>…

try /usr/bin/cmp

ed1k <ed1k@yahoo.com> wrote:

Thanks GUI Group,
I’ll try it if i have it. Where does it come from? I did not find it in helpviewer last night, I
will more careful this night > :wink:
Eduard.

It comes from a base os core packages, so you should have it on your system
Like Brenda said you should have it in /usr/bin.

Regards,

Marcin

GUI Group <> gui@qnx.com> > wrote in article <> 3C3F0E2D.7030707@qnx.com> >…
try /usr/bin/cmp

That’s hilarious. I’m responsible for utils and I never even knew that one
existed. It seems to be about the same as the bindiff.c program (although I
like my output better :wink:

cheers,

Kris
“ed1k” <ed1k@yahoo.com> wrote in message
news:01c19abc$ad946fc0$106fa8c0@ED1K…

Thanks GUI Group,
I’ll try it if i have it. Where does it come from? I did not find it in
helpviewer last night, I
will more careful this night > :wink:
Eduard.

GUI Group <> gui@qnx.com> > wrote in article <> 3C3F0E2D.7030707@qnx.com> >…
try /usr/bin/cmp

ed1k <ed1k@yahoo.com> wrote:

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

diff is intended for text files.

Try using cmp – it is intended for comparing binary files.

-David

QNX Training Services
I do not answer technical questions by email.

David Gibbs <dagibbs@qnx.com> wrote:
: diff is intended for text files.

: Try using cmp – it is intended for comparing binary files.

We’ll mention this in the docs.


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems

Hi,
I believe I looked in section “File and directory manipulation”
in helpviewer when was trying to find right utility. I found diff and diff3, there was not any link
to cmp (there is cmp.html in help directory). There are not any links to diff, diff3 and cmp at the
web:
http://www.qdn.com/support/docs/neutrino/utilities/summary.html#FilesDirectories
This is nice place for these links, is not it?

Since diff’s behaviour for binary files, there must be warning in usage section of diff (better
with reference to cmp)

Best regards,
Eduard.

Steve Reid <stever@qnx.com> wrote in article <a1n70t$fho$1@nntp.qnx.com>…

David Gibbs <> dagibbs@qnx.com> > wrote:
: diff is intended for text files.

: Try using cmp – it is intended for comparing binary files.

We’ll mention this in the docs.


Steve Reid > stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems

Hi,
Thank you Brenda, Marcin and David :wink:
cmp is exactly what I was looking for. Is it posix requirements to print out the address (why it
calls “line number” in doc? “offset” is better, imo) in decimal and bytes in octal? If so, I want
QNX extension: I prefer to see addresses(offsets) and bytes in hex. Is the source available? I want
to add -h option.

Best regards and thank you again,
Eduard.


Tools Mail Account <tools@qnx.com> wrote in article <a1n4is$dmo$1@nntp.qnx.com>…

ed1k <> ed1k@yahoo.com> > wrote:
Thanks GUI Group,
I’ll try it if i have it. Where does it come from? I did not find it in helpviewer last night,
I
will more careful this night > :wink:
Eduard.

It comes from a base os core packages, so you should have it on your system
Like Brenda said you should have it in /usr/bin.

Regards,

Marcin

GUI Group <> gui@qnx.com> > wrote in article <> 3C3F0E2D.7030707@qnx.com> >…
try /usr/bin/cmp

cmp -l file1 file2 | xargs -n3 printf '%x %d %d\n`

It’s not fast (invokes printf for each line), but it works. You could easily
write a little program to replace the xargs printf filter that reads lines
from stdin and writes them to stdout via printf - this would run much
faster than the above if speed is a concern.

“ed1k” <ed1k@yahoo.com> wrote in message
news:01c19ce4$58ab9180$106fa8c0@ED1K…

Hi,
Thank you Brenda, Marcin and David > :wink:
cmp is exactly what I was looking for. Is it posix requirements to print
out the address (why it
calls “line number” in doc? “offset” is better, imo) in decimal and bytes
in octal? If so, I want
QNX extension: I prefer to see addresses(offsets) and bytes in hex. Is the
source available? I want
to add -h option.

Best regards and thank you again,
Eduard.


Tools Mail Account <> tools@qnx.com> > wrote in article
a1n4is$dmo$> 1@nntp.qnx.com> >…
ed1k <> ed1k@yahoo.com> > wrote:
Thanks GUI Group,
I’ll try it if i have it. Where does it come from? I did not find it
in helpviewer last night,
I
will more careful this night > :wink:
Eduard.

It comes from a base os core packages, so you should have it on your
system
Like Brenda said you should have it in /usr/bin.

Regards,

Marcin

GUI Group <> gui@qnx.com> > wrote in article <> 3C3F0E2D.7030707@qnx.com> >…
try /usr/bin/cmp

Come to think of it, awk has a printf command. So just pipe your
output through awk ‘{printf “%x %d %d\n”, $1, $2, $3}’ instead.

“Eric Johnson” <eric@qnx.com> wrote in message
news:a1v3tt$6j3$1@nntp.qnx.com

cmp -l file1 file2 | xargs -n3 printf '%x %d %d\n`

It’s not fast (invokes printf for each line), but it works. You could
easily
write a little program to replace the xargs printf filter that reads lines
from stdin and writes them to stdout via printf - this would run much
faster than the above if speed is a concern.

“ed1k” <> ed1k@yahoo.com> > wrote in message
news:01c19ce4$58ab9180$106fa8c0@ED1K…
Hi,
Thank you Brenda, Marcin and David > :wink:
cmp is exactly what I was looking for. Is it posix requirements to print
out the address (why it
calls “line number” in doc? “offset” is better, imo) in decimal and
bytes
in octal? If so, I want
QNX extension: I prefer to see addresses(offsets) and bytes in hex. Is
the
source available? I want
to add -h option.

Best regards and thank you again,
Eduard.


Tools Mail Account <> tools@qnx.com> > wrote in article
a1n4is$dmo$> 1@nntp.qnx.com> >…
ed1k <> ed1k@yahoo.com> > wrote:
Thanks GUI Group,
I’ll try it if i have it. Where does it come from? I did not find it
in helpviewer last night,
I
will more careful this night > :wink:
Eduard.

It comes from a base os core packages, so you should have it on your
system
Like Brenda said you should have it in /usr/bin.

Regards,

Marcin

GUI Group <> gui@qnx.com> > wrote in article
3C3F0E2D.7030707@qnx.com> >…
try /usr/bin/cmp
\

ed1k <ed1k@yahoo.com> wrote:

Hi,
Thank you Brenda, Marcin and David > :wink:
cmp is exactly what I was looking for. Is it posix requirements to print out the address (why it
calls “line number” in doc? “offset” is better, imo) in decimal and bytes in octal? If so, I want
QNX extension: I prefer to see addresses(offsets) and bytes in hex. Is the source available? I want
to add -h option.

According to ISO/IEC 9945-2:1993(E) docs that is POSIX behaviour. You could
probably write a wrapper (script) to change it to your preference.

Regards,

Marcin

Best regards and thank you again,
Eduard.


Tools Mail Account <> tools@qnx.com> > wrote in article <a1n4is$dmo$> 1@nntp.qnx.com> >…
ed1k <> ed1k@yahoo.com> > wrote:
Thanks GUI Group,
I’ll try it if i have it. Where does it come from? I did not find it in helpviewer last night,
I
will more careful this night > :wink:
Eduard.

It comes from a base os core packages, so you should have it on your system
Like Brenda said you should have it in /usr/bin.

Regards,

Marcin

GUI Group <> gui@qnx.com> > wrote in article <> 3C3F0E2D.7030707@qnx.com> >…
try /usr/bin/cmp

Thank you Marcin and Eric,
Of course, I’m able to write wrapper or my own filter, …or my own cmp utility :wink: No problem, but
I don’t need it at moment :wink: And sure, when I’ll need it, I’ll not have time for it, so Eric’s
suggestions are best and fast… My problem is do not forget them at that moment in future :wink:
Thank you all,
Eduard.