In regen_lib.pl, when opening, first unlink a previous file of that name.
authorNicholas Clark <nick@ccl4.org>
Sun, 23 Jan 2011 09:39:21 +0000 (09:39 +0000)
committerNicholas Clark <nick@ccl4.org>
Sun, 23 Jan 2011 09:39:21 +0000 (09:39 +0000)
Previously regcomp.pl had an explicit unlink for the file it creates, but none
of the other regen/*.pl scripts did. Also, remove commented out code relating
to unlink.

regen/reentr.pl
regen/regcomp.pl
regen/regen_lib.pl

index 3586bc1..963dd96 100644 (file)
@@ -51,7 +51,6 @@ my %map = (
 # Example #3: S_CBI   means type func_r(const char*, char*, int)
 
 
-# safer_unlink 'reentr.h';
 my $h = safer_open("reentr.h-new");
 select $h;
 print read_only_top(lang => 'C', by => 'regen/reentr.pl',
@@ -792,7 +791,6 @@ rename_if_different('reentr.h-new', 'reentr.h');
 
 # Prepare to write the reentr.c.
 
-# safer_unlink 'reentr.c';
 my $c = safer_open("reentr.c-new");
 select $c;
 my $top = read_only_top(lang => 'C', by => 'regen/reentr.pl',
index 913dda5..98a3889 100644 (file)
@@ -17,7 +17,6 @@ BEGIN {
     # Get function prototypes
     require 'regen/regen_lib.pl';
 }
-#use Fatal qw(open close rename chmod unlink);
 use strict;
 
 open DESC, 'regcomp.sym';
@@ -129,8 +128,6 @@ EOP
 
 my $tmp_h = 'regnodes.h-new';
 
-unlink $tmp_h if -f $tmp_h;
-
 my $out = safer_open($tmp_h);
 
 print $out read_only_top(lang => 'C', by => 'regen/regcomp.pl',
index b4d9f86..880a975 100644 (file)
@@ -63,6 +63,9 @@ sub rename_if_different {
 # Saf*er*, but not totally safe. And assumes always open for output.
 sub safer_open {
     my $name = shift;
+    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: $!";
     *{$fh}->{name} = $name;