9 @EXPORT_OK=qw(compare cmp);
11 $File::Compare::VERSION = '1.0';
12 $File::Compare::Too_Big = 1024 * 1024 * 2;
16 use vars qw($\ *FROM *TO);
19 # Version of File::Compare
20 return $File::Compare::VERSION;
24 croak("Usage: compare( file1, file2 [, buffersize]) ")
25 unless(@_ == 2 || @_ == 3);
31 my ($size, $status, $fr, $tr, $fbuf, $tbuf);
35 croak("from undefined") unless (defined $from);
36 croak("to undefined") unless (defined $to);
38 if (ref($from) && (isa($from,'GLOB') || isa($from,'IO::Handle'))) {
40 } elsif (ref(\$from) eq 'GLOB') {
43 open(FROM,"<$from") or goto fail_open1;
48 if (ref($to) && (isa($to,'GLOB') || isa($to,'IO::Handle'))) {
50 } elsif (ref(\$to) eq 'GLOB') {
53 open(TO,"<$to") or goto fail_open2;
59 $size = shift(@_) + 0;
60 croak("Bad buffer size for compare: $size\n") unless ($size > 0);
63 $size = 1024 if ($size < 512);
64 $size = $File::Compare::Too_Big if ($size > $File::Compare::Too_Big);
69 while(defined($fr = read(FROM,$fbuf,$size)) && $fr > 0) {
70 unless (defined($tr = read(TO,$tbuf,$fr)) and $tbuf eq $fbuf) {
74 goto fail_inner if (defined($tr = read(TO,$tbuf,$size)) && $tr > 0);
76 close(TO) || goto fail_open2 if $closeto;
77 close(FROM) || goto fail_open1 if $closefrom;
81 # All of these contortions try to preserve error messages...
83 close(TO) || goto fail_open2 if $closeto;
84 close(FROM) || goto fail_open1 if $closefrom;
93 $! = $status unless $!;