int fd = -1;
char tempname[] = "/tmp/PerlIO_XXXXXX";
const char * const tmpdir = PL_tainting ? NULL : PerlEnv_getenv("TMPDIR");
- SV * const sv = tmpdir && *tmpdir ? newSVpv(tmpdir, 0) : NULL;
+ SV * sv;
/*
* I have no idea how portable mkstemp() is ... NI-S
*/
- if (sv) {
+ if (tmpdir && *tmpdir) {
/* if TMPDIR is set and not empty, we try that first */
+ sv = newSVpv(tmpdir, 0);
sv_catpv(sv, tempname + 4);
fd = mkstemp(SvPVX(sv));
}
if (fd < 0) {
+ sv = NULL;
/* else we try /tmp */
fd = mkstemp(tempname);
}
require './test.pl';
}
-plan tests => 40;
+plan tests => 42;
use_ok('PerlIO');
if !$Config{d_mkstemp}
|| $^O eq 'VMS' || $^O eq 'MSwin32' || $^O eq 'os2';
local $ENV{TMPDIR} = $nonexistent;
+
+ # hardcoded default temp path
+ my $perlio_tmp_file_glob = '/tmp/PerlIO_??????';
+
+ my @before = glob $perlio_tmp_file_glob;
+
ok( open(my $x,"+<",undef), 'TMPDIR honored by magic temp file via 3 arg open with undef - works if TMPDIR points to a non-existent dir');
+ my @after = glob $perlio_tmp_file_glob;
+ is( "@after", "@before", "No tmp files leaked");
+
+ unlink_new(\@before, \@after);
+
mkdir $ENV{TMPDIR};
ok(open(my $x,"+<",undef), 'TMPDIR honored by magic temp file via 3 arg open with undef - works if TMPDIR points to an existent dir');
- # hardcoded default temp path
- unlink </tmp/PerlIO_*>;
+ @after = glob $perlio_tmp_file_glob;
+ is( "@after", "@before", "No tmp files leaked");
+
+ unlink_new(\@before, \@after);
}
}
+sub unlink_new {
+ my ($before, $after) = @_;
+ my %before;
+ @before{@$before} = ();
+ unlink grep {!exists $before{$_}} @$after;
+}
+
# in-memory open
SKIP: {
eval { require PerlIO::scalar };