Home | History | Annotate | Line # | Download | only in ms
      1  1.1  christos #! /usr/bin/env perl
      2  1.1  christos # Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
      3  1.1  christos #
      4  1.1  christos # Licensed under the Apache License 2.0 (the "License").  You may not use
      5  1.1  christos # this file except in compliance with the License.  You can obtain a copy
      6  1.1  christos # in the file LICENSE in the source distribution or at
      7  1.1  christos # https://www.openssl.org/source/license.html
      8  1.1  christos 
      9  1.1  christos ($#ARGV == 1) || die "usage: cmp.pl <file1> <file2>\n";
     10  1.1  christos 
     11  1.1  christos open(IN0,"<$ARGV[0]") || die "unable to open $ARGV[0]\n";
     12  1.1  christos open(IN1,"<$ARGV[1]") || die "unable to open $ARGV[1]\n";
     13  1.1  christos binmode IN0;
     14  1.1  christos binmode IN1;
     15  1.1  christos 
     16  1.1  christos $tot=0;
     17  1.1  christos $ret=1;
     18  1.1  christos for (;;)
     19  1.1  christos {
     20  1.1  christos     $n1=sysread(IN0,$b1,4096);
     21  1.1  christos     $n2=sysread(IN1,$b2,4096);
     22  1.1  christos 
     23  1.1  christos     last if ($n1 != $n2);
     24  1.1  christos     last if ($b1 ne $b2);
     25  1.1  christos     last if ($n1 < 0);
     26  1.1  christos     if ($n1 == 0)
     27  1.1  christos     {
     28  1.1  christos         $ret=0;
     29  1.1  christos         last;
     30  1.1  christos     }
     31  1.1  christos     $tot+=$n1;
     32  1.1  christos }
     33  1.1  christos 
     34  1.1  christos close(IN0);
     35  1.1  christos close(IN1);
     36  1.1  christos if ($ret)
     37  1.1  christos {
     38  1.1  christos     printf STDERR "$ARGV[0] and $ARGV[1] are different\n";
     39  1.1  christos     @a1=unpack("C*",$b1);
     40  1.1  christos     @a2=unpack("C*",$b2);
     41  1.1  christos     for ($i=0; $i<=$#a1; $i++)
     42  1.1  christos     {
     43  1.1  christos         if ($a1[$i] ne $a2[$i])
     44  1.1  christos         {
     45  1.1  christos             printf "%02X %02X <<\n",$a1[$i],$a2[$i];
     46  1.1  christos             last;
     47  1.1  christos         }
     48  1.1  christos     }
     49  1.1  christos     $nm=$tot+$n1;
     50  1.1  christos     $tot+=$i+1;
     51  1.1  christos     printf STDERR "diff at char $tot of $nm\n";
     52  1.1  christos }
     53  1.1  christos exit($ret);
     54