diff options
-rw-r--r-- | bin/autom4te.in | 18 | ||||
-rw-r--r-- | bin/autoreconf.in | 7 |
2 files changed, 9 insertions, 16 deletions
diff --git a/bin/autom4te.in b/bin/autom4te.in index 9aa0d1f1..e54fa145 100644 --- a/bin/autom4te.in +++ b/bin/autom4te.in @@ -548,7 +548,7 @@ sub handle_output ($$) # Read the (cached) raw M4 output, produce the actual result. # If we are writing to a regular file, replace it atomically. - my $atomic_replace = 0; + my $scratchfile; my $out; if ($output eq '-') { @@ -564,18 +564,14 @@ sub handle_output ($$) { my (undef, $outdir, undef) = fileparse ($output); - use File::Temp (); - $out = new File::Temp (UNLINK => 0, DIR => $outdir); + use File::Temp qw (tempfile); + ($out, $scratchfile) = tempfile (UNLINK => 0, DIR => $outdir); fatal "cannot create a file in $outdir: $!" unless $out; # File::Temp doesn't give us access to 3-arg open(2), unfortunately. - # In older Perls, implicit conversion of a File::Temp to its filename - # cannot be relied upon. - chmod (oct ($mode) & ~(umask), $out->filename) - or fatal "setting mode of " . $out->filename . ": $!"; - - $atomic_replace = 1; + chmod (oct ($mode) & ~(umask), $scratchfile) + or fatal "setting mode of " . $scratchfile . ": $!"; } my $in = new Autom4te::XFile ($ocache . $req->id, "<"); @@ -613,8 +609,8 @@ sub handle_output ($$) } $out->close(); - update_file ($out->filename, $output, $force) - if $atomic_replace; + update_file ($scratchfile, $output, $force) + if defined $scratchfile; # If no forbidden words, we're done. return diff --git a/bin/autoreconf.in b/bin/autoreconf.in index ec0a12e2..e564d18c 100644 --- a/bin/autoreconf.in +++ b/bin/autoreconf.in @@ -46,7 +46,7 @@ BEGIN # Do not use Cwd::chdir, since it might hang. use Cwd qw (cwd); use File::Copy qw (copy); -use File::Temp (); +use File::Temp qw (tempfile); use Autom4te::ChannelDefs; use Autom4te::Channels; @@ -362,10 +362,7 @@ sub install_aux_file unlink $dest or fatal "rm -f $dest: $!\n"; } - my $temp = new File::Temp (UNLINK => 0, DIR => $destdir); - # Older Perls don't convert $temp to its filename - # in all the places we need it to. - my $tempname = $temp->filename; + my ($temp, $tempname) = tempfile (UNLINK => 0, DIR => $destdir); copy ($src, $tempname) or fatal "copying $src to $tempname: $!\n"; make_executable ($tempname) if -x $src; |