File: hex_comp.cpp

package info (click to toggle)
pluto-jpl-eph 0.0~git20180228-1.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 684 kB
  • sloc: cpp: 2,350; sh: 277; makefile: 131; perl: 64
file content (32 lines) | stat: -rw-r--r-- 966 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

int main( const int argc, const char **argv)
{
   FILE *ifile1 = fopen( argv[1], "rb");
   FILE *ifile2 = fopen( argv[2], "rb");
   size_t bytes_read1, bytes_read2, loc = 0;
   const size_t buffsize = 32768;
   unsigned char *ibuff1 = (unsigned char *)malloc( buffsize * 2);
   unsigned char *ibuff2 = ibuff1 + buffsize;

   assert( ifile1);
   assert( ifile2);
   assert( ibuff1);
   while( (bytes_read1 = fread( ibuff1, 1, buffsize, ifile1)) != 0 &&
          (bytes_read2 = fread( ibuff2, 1, buffsize, ifile2)) != 0)
      {
      size_t i;

      assert( bytes_read1 == bytes_read2);
      if( memcmp( ibuff1, ibuff2, bytes_read1))
         for( i = 0; i < bytes_read1; i++)
            if( ibuff1[i] != ibuff2[i])
               printf( "%8lx: %02x %02x %zd\n",
                           loc + i, ibuff1[i], ibuff2[i], loc + i);
      loc += bytes_read1;
      }
   return( 0);
}