From: Niko Tyni Date: Wed, 10 Jun 2009 13:32:42 +0000 (-0500) Subject: [perl #66452] TMPDIR not honored when opening an anonymous temporary file X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=26e8050aaf2eeca2f04cdc7bc5df07f8dc4ff0f9;p=p5sagit%2Fp5-mst-13.2.git [perl #66452] TMPDIR not honored when opening an anonymous temporary file --- diff --git a/perlio.c b/perlio.c index e92a32a..89718e9 100644 --- a/perlio.c +++ b/perlio.c @@ -5174,7 +5174,9 @@ PerlIO_tmpfile(void) f = PerlIO_fdopen(fd, "w+b"); #else /* WIN32 */ # if defined(HAS_MKSTEMP) && ! defined(VMS) && ! defined(OS2) - SV * const sv = newSVpvs("/tmp/PerlIO_XXXXXX"); + const char * const tmpdir = PerlEnv_getenv("TMPDIR"); + SV * const sv = newSVpv(tmpdir ? tmpdir : "/tmp", 0); + sv_catpv(sv, "/PerlIO_XXXXXX"); /* * I have no idea how portable mkstemp() is ... NI-S */ diff --git a/t/io/perlio.t b/t/io/perlio.t index c145945..8d76d91 100644 --- a/t/io/perlio.t +++ b/t/io/perlio.t @@ -8,13 +8,14 @@ BEGIN { } } -use Test::More tests => 37; +use Test::More tests => 39; use_ok('PerlIO'); my $txt = "txt$$"; my $bin = "bin$$"; my $utf = "utf$$"; +my $nonexistent = "nex$$"; my $txtfh; my $binfh; @@ -89,6 +90,17 @@ ok(close($utffh)); # report after STDOUT is restored ok($status, ' re-open STDOUT'); close OLDOUT; + + SKIP: { + skip("TMPDIR not honored on this platform", 2) + if !$Config{d_mkstemp} + || $^O eq 'VMS' || $^O eq 'MSwin32' || $^O eq 'os2'; + local $ENV{TMPDIR} = $nonexistent; + ok( !open(my $x,"+<",undef), 'TMPDIR honored by magic temp file via 3 arg open with undef - fails if TMPDIR points to a non-existent dir'); + + 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'); + } } # in-memory open @@ -136,5 +148,6 @@ END { 1 while unlink $txt; 1 while unlink $bin; 1 while unlink $utf; + 1 while rmdir $nonexistent; }