perlio.c, PerlIO_tmpfile: Fall back to cwd if we have no /tmp or $TMPDIR
authorBrian Fraser <fraserbn@gmail.com>
Wed, 22 Jan 2014 01:45:17 +0000 (22:45 -0300)
committerBrian Fraser <fraserbn@gmail.com>
Wed, 22 Jan 2014 01:45:17 +0000 (22:45 -0300)
With this, open($fh, undef) will now work on systems without
a /tmp (or equivalent) where TMPDIR is not set.

perlio.c

index 5d41e76..ec19bfe 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -4971,6 +4971,12 @@ PerlIO_tmpfile(void)
         /* else we try /tmp */
         fd = mkstemp(tempname);
      }
+     if (fd < 0) {
+         /* Try cwd */
+         sv = newSVpvs(".");
+         sv_catpv(sv, tempname + 4);
+         fd = mkstemp(SvPVX(sv));
+     }
      if (fd >= 0) {
          f = PerlIO_fdopen(fd, "w+");
          if (f)