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