04bfb0
From 0424723402ef153af8ee44222315d9b6a818d1ba Mon Sep 17 00:00:00 2001
04bfb0
From: Tony Cook <tony@develop-help.com>
04bfb0
Date: Tue, 2 Jul 2019 15:22:26 +1000
04bfb0
Subject: [PATCH 2/3] (perl #134221) support append mode temp files on Win32
04bfb0
 too
04bfb0
MIME-Version: 1.0
04bfb0
Content-Type: text/plain; charset=UTF-8
04bfb0
Content-Transfer-Encoding: 8bit
04bfb0
04bfb0
Signed-off-by: Petr Písař <ppisar@redhat.com>
04bfb0
---
04bfb0
 perlio.c         |  2 +-
04bfb0
 win32/win32.c    | 10 +++++++++-
04bfb0
 win32/win32iop.h |  1 +
04bfb0
 3 files changed, 11 insertions(+), 2 deletions(-)
04bfb0
04bfb0
diff --git a/perlio.c b/perlio.c
04bfb0
index a737e79e02..81ebc156ad 100644
04bfb0
--- a/perlio.c
04bfb0
+++ b/perlio.c
04bfb0
@@ -5059,7 +5059,7 @@ PerlIO_tmpfile_flags(int imode)
04bfb0
 #endif
04bfb0
      PerlIO *f = NULL;
04bfb0
 #ifdef WIN32
04bfb0
-     const int fd = win32_tmpfd();
04bfb0
+     const int fd = win32_tmpfd_mode(imode);
04bfb0
      if (fd >= 0)
04bfb0
 	  f = PerlIO_fdopen(fd, "w+b");
04bfb0
 #elif ! defined(VMS) && ! defined(OS2)
04bfb0
diff --git a/win32/win32.c b/win32/win32.c
04bfb0
index 8104d864c2..91fdffe09b 100644
04bfb0
--- a/win32/win32.c
04bfb0
+++ b/win32/win32.c
04bfb0
@@ -2907,10 +2907,18 @@ win32_rewind(FILE *pf)
04bfb0
 
04bfb0
 DllExport int
04bfb0
 win32_tmpfd(void)
04bfb0
+{
04bfb0
+    return win32_tmpfd_mode(0);
04bfb0
+}
04bfb0
+
04bfb0
+DllExport int
04bfb0
+win32_tmpfd_mode(int mode)
04bfb0
 {
04bfb0
     char prefix[MAX_PATH+1];
04bfb0
     char filename[MAX_PATH+1];
04bfb0
     DWORD len = GetTempPath(MAX_PATH, prefix);
04bfb0
+    mode &= ~( O_ACCMODE | O_CREAT | O_EXCL );
04bfb0
+    mode |= O_RDWR;
04bfb0
     if (len && len < MAX_PATH) {
04bfb0
 	if (GetTempFileName(prefix, "plx", 0, filename)) {
04bfb0
 	    HANDLE fh = CreateFile(filename,
04bfb0
@@ -2922,7 +2930,7 @@ win32_tmpfd(void)
04bfb0
 				   | FILE_FLAG_DELETE_ON_CLOSE,
04bfb0
 				   NULL);
04bfb0
 	    if (fh != INVALID_HANDLE_VALUE) {
04bfb0
-		int fd = win32_open_osfhandle((intptr_t)fh, 0);
04bfb0
+		int fd = win32_open_osfhandle((intptr_t)fh, mode);
04bfb0
 		if (fd >= 0) {
04bfb0
 		    PERL_DEB(dTHX;)
04bfb0
 		    DEBUG_p(PerlIO_printf(Perl_debug_log,
04bfb0
diff --git a/win32/win32iop.h b/win32/win32iop.h
04bfb0
index 53330e5951..559e1f9cd2 100644
04bfb0
--- a/win32/win32iop.h
04bfb0
+++ b/win32/win32iop.h
04bfb0
@@ -64,6 +64,7 @@ DllExport  int		win32_fgetpos(FILE *pf,fpos_t *p);
04bfb0
 DllExport  int		win32_fsetpos(FILE *pf,const fpos_t *p);
04bfb0
 DllExport  void		win32_rewind(FILE *pf);
04bfb0
 DllExport  int		win32_tmpfd(void);
04bfb0
+DllExport  int		win32_tmpfd_mode(int mode);
04bfb0
 DllExport  FILE*	win32_tmpfile(void);
04bfb0
 DllExport  void		win32_abort(void);
04bfb0
 DllExport  int  	win32_fstat(int fd,Stat_t *sbufptr);
04bfb0
-- 
04bfb0
2.20.1
04bfb0