2
0

cmp.pl 1.2 KB

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