--- netpbm-10.29/editor/pnmquant- 2005-04-27 16:03:17 +0000 +++ netpbm-10.29/editor/pnmquant 2005-10-04 17:04:23 +0000 @@ -11,33 +11,23 @@ use strict; use English; use Getopt::Long; -#use File::Temp "tempfile"; # not available before Perl 5.6.1 use File::Spec; #use Fcntl ":seek"; # not available in Perl 5.00503 use Fcntl; # gets open flags my ($TRUE, $FALSE) = (1,0); +use File::Spec; +use File::Temp qw(tempfile); +use sigtrap qw(die normal-signals); + my ($SEEK_SET, $SEEK_CUR, $SEEK_END) = (0, 1, 2); sub tempFile($) { - -# Here's what we'd do if we could expect Perl 5.6.1 or later, instead -# of calling this subroutine: -# my ($file, $filename) = tempfile("pnmquant_XXXX", -# SUFFIX=>".pnm", -# DIR=>File::Spec->tmpdir()) -# UNLINK=>$TRUE); - my ($suffix) = @_; - my $fileName; - local *file; # For some inexplicable reason, must be local, not my - my $i; - $i = 0; - do { - $fileName = File::Spec->tmpdir() . "/pnmquant_" . $i++ . $suffix; - } until sysopen(*file, $fileName, O_RDWR|O_CREAT|O_EXCL); - - return(*file, $fileName); + my $suffix = shift; + my ($fh, $fname) = tempfile("pnmquant.XXXXXXXX", + SUFFIX => $suffix, DIR => File::Spec->tmpdir(), UNLINK => 1); + return($fh, $fname); }