diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-05-14 17:22:55 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-05-19 10:18:14 +0100 |
commit | 73437b648f94e4d46b3838d3721a6f9c2985ac2b (patch) | |
tree | 474891e182740f43b6d7c566b4d8d446c55d6db6 /regen | |
parent | 29c22b52682692a630218342d1997c803a3b487b (diff) | |
download | perl-73437b648f94e4d46b3838d3721a6f9c2985ac2b.tar.gz |
Add an optional 'mode' argument to open_new(), to open for appending.
Use this in regen/uconfig_h.pl
Diffstat (limited to 'regen')
-rw-r--r-- | regen/regen_lib.pl | 16 | ||||
-rwxr-xr-x | regen/uconfig_h.pl | 6 |
2 files changed, 14 insertions, 8 deletions
diff --git a/regen/regen_lib.pl b/regen/regen_lib.pl index 951c23b431..c56f56435c 100644 --- a/regen/regen_lib.pl +++ b/regen/regen_lib.pl @@ -62,13 +62,19 @@ sub rename_if_different { # Open a new file. sub open_new { - my ($final_name) = @_; + my ($final_name, $mode) = @_; my $name = $final_name . '-new'; - if (-f $name) { - unlink $name or die "$name exists but can't unlink: $!"; - } my $fh = gensym; - open $fh, ">$name" or die "Can't create $name: $!"; + if (!defined $mode or $mode eq '>') { + if (-f $name) { + unlink $name or die "$name exists but can't unlink: $!"; + } + open $fh, ">$name" or die "Can't create $name: $!"; + } elsif ($mode eq '>>') { + open $fh, ">>$name" or die "Can't append to $name: $!"; + } else { + die "Unhandled open mode '$mode#"; + } *{$fh}->{name} = $name; *{$fh}->{final_name} = $final_name; *{$fh}->{lang} = ($final_name =~ /\.(?:c|h|tab|act)$/ ? 'C' : 'Perl'); diff --git a/regen/uconfig_h.pl b/regen/uconfig_h.pl index 8f714e2877..0e2feaf194 100755 --- a/regen/uconfig_h.pl +++ b/regen/uconfig_h.pl @@ -22,9 +22,9 @@ safer_unlink($uconfig_h_new); my $command = 'sh ./config_h.SH'; system $command and die "`$command` failed, \$?=$?"; -open FH, ">>$uconfig_h_new" or die "Can't append to $uconfig_h_new: $!"; +my $fh = open_new($uconfig_h, '>>'); -print FH "\n", read_only_bottom([$ENV{CONFIG_SH}, 'config_h.SH']); +print $fh "\n", read_only_bottom([$ENV{CONFIG_SH}, 'config_h.SH']); -safer_close(*FH); +safer_close($fh); rename_if_different($uconfig_h_new, $uconfig_h); |