Skip to content

Commit 4239cb9

Browse files
authored
patch: simplify --check (#706)
* patch: simpler --check code * "patch --check" can be implemented in less code using File::Temp to provide a garbage filehandle which is automatically cleaned up later * I tested this by repeatedly running "perl patch -C original.c my.diff"; original.c is not modified so each instance is successful * no need for o_fh & o_dh to be a different file
1 parent ea56ff0 commit 4239cb9

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

bin/patch

+4-26
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ License: perl
1818

1919
use strict;
2020

21+
use File::Temp qw();
22+
2123
my $VERSION = '0.28';
2224

2325
$|++;
@@ -428,22 +430,17 @@ sub bless {
428430
$self->{i_fh} = *IN; # input filehandle
429431
$self->{i_file} = $in; # input filename
430432

431-
# Like /dev/null
432-
local *NULL;
433-
tie *NULL, 'Dev::Null';
434-
435433
# Open output file.
436434
if ($self->{check}) {
437-
$self->{o_fh} = *NULL; # output filehandle
438-
$self->{d_fh} = *NULL; # ifdef filehandle
435+
$self->{'o_fh'} = $self->{'d_fh'} = File::Temp->new();
439436
} else {
440437
local *OUT;
441438
open OUT, '+>', $out or $self->skip("Couldn't open OUTFILE: $!\n");
442439
binmode OUT;
443440
$|++, select $_ for select OUT;
444441
$self->{o_fh} = *OUT;
445442
$self->{o_file} = $out;
446-
$self->{d_fh} = length $self->{ifdef} ? *OUT : *NULL;
443+
$self->{d_fh} = length $self->{ifdef} ? *OUT : File::Temp->new();
447444
}
448445

449446
$self->{'reject-file'} = "$out.rej" unless defined $self->{'reject-file'};
@@ -1105,25 +1102,6 @@ sub CLOSE {
11051102
$self = undef;
11061103
}
11071104

1108-
1109-
1110-
1111-
package
1112-
Dev::Null; # hide from PAUSE
1113-
1114-
# Create filehandles that go nowhere.
1115-
1116-
sub TIEHANDLE { bless \my $null }
1117-
sub PRINT {}
1118-
sub PRINTF {}
1119-
sub WRITE {}
1120-
sub READLINE {''}
1121-
sub READ {''}
1122-
sub GETC {''}
1123-
1124-
1125-
1126-
11271105
__END__
11281106
11291107
=head1 NAME

0 commit comments

Comments
 (0)