Debian Codegraph @

script/crc32

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/perl
2
3 # Computes and prints to stdout the CRC-32 values of the given files
4
5 use 5.006;
6 use strict;
7 use lib qw( blib/lib lib );
8 use Archive::Zip;
9 use FileHandle;
10
11 use vars qw( $VERSION );
12 BEGIN {
13 $VERSION = '1.51';
14 }
15
16 my $totalFiles = scalar(@ARGV);
17 foreach my $file (@ARGV) {
18 if ( -d $file ) {
19 warn "$0: ${file}: Is a directory\n";
20 next;
21 }
22 my $fh = FileHandle->new();
23 if ( !$fh->open( $file, 'r' ) ) {
24 warn "$0: $!\n";
25 next;
26 }
27 binmode($fh);
28 my $buffer;
29 my $bytesRead;
30 my $crc = 0;
31 while ( $bytesRead = $fh->read( $buffer, 32768 ) ) {
32 $crc = Archive::Zip::computeCRC32( $buffer, $crc );
33 }
34 my $fileCrc = sprintf("%08x", $crc);
35 printf("$fileCrc");
36 print("\t$file") if ( $totalFiles > 1 );
37
38 if ( $file =~ /[^[:xdigit:]]([[:xdigit:]]{8})[^[:xdigit:]]/ ) {
39 my $filenameCrc = $1;
40 if ( lc($filenameCrc) eq lc($fileCrc) ) {
41 print("\tOK")
42 } else {
43 print("\tBAD $fileCrc != $filenameCrc");
44 }
45 }
46
47 print("\n");
48 }