package File::Compare;
+use strict;
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $Too_Big *FROM *TO);
+
require Exporter;
use Carp;
use UNIVERSAL qw(isa);
-@ISA=qw(Exporter);
-@EXPORT=qw(compare);
-@EXPORT_OK=qw(compare cmp);
-
-$File::Compare::VERSION = '1.0';
-$File::Compare::Too_Big = 1024 * 1024 * 2;
+$VERSION = '1.1001';
+@ISA = qw(Exporter);
+@EXPORT = qw(compare);
+@EXPORT_OK = qw(cmp);
-
-use strict;
-use vars qw($\ *FROM *TO);
+$Too_Big = 1024 * 1024 * 2;
sub VERSION {
# Version of File::Compare
my $to = shift;
my $closefrom=0;
my $closeto=0;
- my ($size, $status, $fr, $tr, $fbuf, $tbuf);
+ my ($size, $fromsize, $status, $fr, $tr, $fbuf, $tbuf);
local(*FROM, *TO);
local($\) = '';
open(FROM,"<$from") or goto fail_open1;
binmode FROM;
$closefrom = 1;
+ $fromsize = -s FROM;
}
if (ref($to) && (isa($to,'GLOB') || isa($to,'IO::Handle'))) {
$closeto = 1;
}
+ if ($closefrom && $closeto) {
+ # If both are opened files we know they differ if their size differ
+ goto fail_inner if $fromsize != -s TO;
+ }
+
if (@_) {
$size = shift(@_) + 0;
croak("Bad buffer size for compare: $size\n") unless ($size > 0);
} else {
- $size = -s FROM;
+ $size = $fromsize;
$size = 1024 if ($size < 512);
- $size = $File::Compare::Too_Big if ($size > $File::Compare::Too_Big);
+ $size = $Too_Big if ($size > $Too_Big);
}
$fbuf = '';
*cmp = \&compare;
+1;
+
+__END__
+
+=head1 NAME
+
+File::Compare - Compare files or filehandles
+
+=head1 SYNOPSIS
+
+ use File::Compare;
+
+ if (compare("file1","file2") == 0) {
+ print "They're equal\n";
+ }
+
+=head1 DESCRIPTION
+
+The File::Compare::compare function compares the contents of two
+sources, each of which can be a file or a file handle. It is exported
+from File::Compare by default.
+
+File::Compare::cmp is a synonym for File::Compare::compare. It is
+exported from File::Compare only by request.
+
+=head1 RETURN
+
+File::Compare::compare return 0 if the files are equal, 1 if the
+files are unequal, or -1 if an error was encountered.
+
+=head1 AUTHOR
+
+File::Compare was written by Nick Ing-Simmons.
+Its original documentation was written by Chip Salzenberg.
+
+=cut
+