From: Gurusamy Sarathy <gsar@cpan.org>
Date: Mon, 2 Jun 2003 18:44:34 +0000 (+0000)
Subject: don't use File::Temp to implement PerlIO_tmpfile() on windows;
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3a8ae1affddf8a9aac8746965f2ae13c7af42aba;p=p5sagit%2Fp5-mst-13.2.git

don't use File::Temp to implement PerlIO_tmpfile() on windows;
reuse the straightforward native implementation instead

this fixes the warning from io_xs.t

NOTE: File::Temp has a less-than-robust implementation on windows
that relies on END blocks being run (this may not happen always)

p4raw-id: //depot/perl@19667
---

diff --git a/op.c b/op.c
index 75adb17..cbf19d2 100644
--- a/op.c
+++ b/op.c
@@ -6511,15 +6511,21 @@ const_sv_xsub(pTHX_ CV* cv)
     XSRETURN(1);
 }
 
+/* XXX this belongs in doio.c, not here */
 PerlIO*
 Perl_my_tmpfp(pTHX)
 {
      PerlIO *f = NULL;
      int fd = -1;
-#ifdef PERL_EXTERNAL_GLOB
+#ifdef WIN32
+     fd = win32_tmpfd();
+     if (fd >= 0)
+	 f = PerlIO_fdopen(fd, "w+b");
+#else
+#  ifdef PERL_EXTERNAL_GLOB
      /* File::Temp pulls in Fcntl, which may not be available with
       *  e.g. miniperl, use mkstemp() or stdio tmpfile() instead. */
-#   if defined(WIN32) || !defined(HAS_MKSTEMP)
+#    if defined(WIN32) || !defined(HAS_MKSTEMP)
      FILE *stdio = PerlSIO_tmpfile();
 
      if (stdio) {
@@ -6531,7 +6537,7 @@ Perl_my_tmpfp(pTHX)
                     s->stdio = stdio;
           }
      }
-#   else /* !WIN32 && HAS_MKSTEMP */
+#    else /* !WIN32 && HAS_MKSTEMP */
      SV *sv = newSVpv("/tmp/PerlIO_XXXXXX", 0);
 
      if (sv) {
@@ -6544,8 +6550,8 @@ Perl_my_tmpfp(pTHX)
                }
           }
      }
-#   endif /* WIN32 || !HAS_MKSTEMP */
-#else
+#    endif /* !HAS_MKSTEMP */
+#  else
      /* We have internal glob, which probably also means that we 
       * can also use File::Temp (which uses Fcntl) with impunity. */
      GV *gv = gv_fetchpv("File::Temp::tempfile", FALSE, SVt_PVCV);
@@ -6582,8 +6588,8 @@ Perl_my_tmpfp(pTHX)
           FREETMPS;
           LEAVE;
      }
+#  endif
 #endif
 
      return f;
 }
-
diff --git a/win32/win32.c b/win32/win32.c
index c409203..d059fe2 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -2615,8 +2615,8 @@ win32_rewind(FILE *pf)
     return;
 }
 
-DllExport FILE*
-win32_tmpfile(void)
+DllExport int
+win32_tmpfd(void)
 {
     dTHX;
     char prefix[MAX_PATH+1];
@@ -2640,11 +2640,20 @@ win32_tmpfile(void)
 #endif
 		    DEBUG_p(PerlIO_printf(Perl_debug_log,
 					  "Created tmpfile=%s\n",filename));
-		    return fdopen(fd, "w+b");
+		    return fd;
 		}
 	    }
 	}
     }
+    return -1;
+}
+
+DllExport FILE*
+win32_tmpfile(void)
+{
+    int fd = win32_tmpfd();
+    if (fd >= 0)
+	return win32_fdopen(fd, "w+b");
     return NULL;
 }
 
diff --git a/win32/win32iop.h b/win32/win32iop.h
index e835b2e..1683e97 100644
--- a/win32/win32iop.h
+++ b/win32/win32iop.h
@@ -67,6 +67,7 @@ DllExport  int		win32_fseek(FILE *pf,Off_t offset,int origin);
 DllExport  int		win32_fgetpos(FILE *pf,fpos_t *p);
 DllExport  int		win32_fsetpos(FILE *pf,const fpos_t *p);
 DllExport  void		win32_rewind(FILE *pf);
+DllExport  int		win32_tmpfd(void);
 DllExport  FILE*	win32_tmpfile(void);
 DllExport  void		win32_abort(void);
 DllExport  int  	win32_fstat(int fd,Stat_t *sbufptr);