Skip to content

Commit b1781b7

Browse files
authored
patch: patchfile argument may not be a directory
* Test case: perl patch orig.c . * Original file to patch is a regular file, patchfile argument is a directory * Previously patch would exit(0) for this case, but doing this fails to notify the user that anything went wrong * Tested against GNU version
1 parent ec49969 commit b1781b7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

bin/patch

+10-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use constant EX_SUCCESS => 0;
2424
use constant EX_REJECTS => 1;
2525
use constant EX_FAILURE => 2;
2626

27-
my $VERSION = '0.29';
27+
my $VERSION = '0.30';
2828

2929
$|++;
3030

@@ -1092,13 +1092,18 @@ package
10921092

10931093
sub TIEHANDLE {
10941094
my ($class, $file) = @_;
1095-
local *FH;
1095+
my $fh;
10961096
if ($file eq '-') {
1097-
*FH = *STDIN;
1097+
$fh = *STDIN;
10981098
} else {
1099-
open *FH, '<', $file or return;
1099+
if (-d $file) {
1100+
die "$0: '$file' is a directory\n";
1101+
}
1102+
unless (open $fh, '<', $file) {
1103+
die "$0: failed to open '$file': $!\n";
1104+
}
11001105
}
1101-
bless [*FH], $class;
1106+
bless [$fh], $class;
11021107
}
11031108

11041109
sub READLINE {

0 commit comments

Comments
 (0)