netpbm/netpbm-tmpfile.patch

64 lines
1.7 KiB
Diff
Raw Normal View History

Index: editor/pnmindex.csh
===================================================================
--- editor/pnmindex.csh.orig
+++ editor/pnmindex.csh
@@ -85,7 +85,7 @@ if ( $#argv == 0 ) then
goto usage
endif
-set tmpfile=/tmp/pi.tmp.$$
+set tmpfile=.pi.tmp.$$
rm -f $tmpfile
set maxformat=PBM
Index: generator/ppmrainbow
===================================================================
--- generator/ppmrainbow.orig
+++ generator/ppmrainbow
@@ -25,6 +25,7 @@ exec perl -w -x -S -- "$0" "$@"
#!/usr/bin/perl
use strict;
use Getopt::Long;
+use File::Temp qw{tempfile tempdir};
my ($FALSE, $TRUE) = (0,1);
@@ -71,31 +72,25 @@ if (!$norepeat) {
push @colorlist, $ARGV[0];
}
-my $ourtmp = "$tmpdir/ppmrainbow$$";
-mkdir($ourtmp, 0777) or
- die("Unable to create directory for temporary files '$ourtmp");
-
-
+my $ourtmp = tempdir("ppmrainbow.XXXX", DIR => $tmpdir, CLEANUP => 1);
my $widthRemaining;
-my $n;
my @outlist;
-$n = 0;
$widthRemaining = $Twid;
@outlist = ();
while (@colorlist >= 2) {
- my $outfile = sprintf("%s/file.%03u.ppm", $ourtmp, $n);
+ (my $tmpfh, my $outfile) = tempfile("file.XXXXXXXX", DIR => "$ourtmp", SUFFIX => '.ppm');
push(@outlist, $outfile);
my $w = int(($widthRemaining-1)/(@colorlist-1))+1;
- my $rc = system("$verboseCommand pgmramp -lr $w $Thgt | " .
- "pgmtoppm \"$colorlist[0]-$colorlist[1]\" >$outfile");
- if ($rc != 0) {
+ my $content = qx{$verboseCommand pgmramp -lr $w $Thgt |
+ pgmtoppm "$colorlist[0]-$colorlist[1]"};
+ if (! "$content") {
fatal("pgmramp|pgmtoppm failed.");
}
+ print $tmpfh $content;
$widthRemaining -= $w;
- $n++;
shift @colorlist;
}