In perl.git, the branch tonyc/134221-open-temp-modes has been updated <https://perl5.git.perl.org/perl.git/commitdiff/6a0e219b617bcb21c24f1f2e22394cbb62125a03?hp=d55e40faa52d1a9ff4da5a8806fe4224f2e9455e>
- Log ----------------------------------------------------------------- commit 6a0e219b617bcb21c24f1f2e22394cbb62125a03 Author: Tony Cook <t...@develop-help.com> Date: Tue Jul 2 15:22:26 2019 +1000 (perl #134221) support append mode temp files on Win32 too ----------------------------------------------------------------------- Summary of changes: perlio.c | 2 +- win32/win32.c | 10 +++++++++- win32/win32iop.h | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/perlio.c b/perlio.c index 289e824be9..55cb07d1d7 100644 --- a/perlio.c +++ b/perlio.c @@ -5059,7 +5059,7 @@ PerlIO_tmpfile_flags(int imode) #endif PerlIO *f = NULL; #ifdef WIN32 - const int fd = win32_tmpfd(); + const int fd = win32_tmpfd_mode(imode); if (fd >= 0) f = PerlIO_fdopen(fd, "w+b"); #elif ! defined(VMS) && ! defined(OS2) diff --git a/win32/win32.c b/win32/win32.c index 8104d864c2..91fdffe09b 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2907,10 +2907,18 @@ win32_rewind(FILE *pf) DllExport int win32_tmpfd(void) +{ + return win32_tmpfd_mode(0); +} + +DllExport int +win32_tmpfd_mode(int mode) { char prefix[MAX_PATH+1]; char filename[MAX_PATH+1]; DWORD len = GetTempPath(MAX_PATH, prefix); + mode &= ~( O_ACCMODE | O_CREAT | O_EXCL ); + mode |= O_RDWR; if (len && len < MAX_PATH) { if (GetTempFileName(prefix, "plx", 0, filename)) { HANDLE fh = CreateFile(filename, @@ -2922,7 +2930,7 @@ win32_tmpfd(void) | FILE_FLAG_DELETE_ON_CLOSE, NULL); if (fh != INVALID_HANDLE_VALUE) { - int fd = win32_open_osfhandle((intptr_t)fh, 0); + int fd = win32_open_osfhandle((intptr_t)fh, mode); if (fd >= 0) { PERL_DEB(dTHX;) DEBUG_p(PerlIO_printf(Perl_debug_log, diff --git a/win32/win32iop.h b/win32/win32iop.h index 53330e5951..559e1f9cd2 100644 --- a/win32/win32iop.h +++ b/win32/win32iop.h @@ -64,6 +64,7 @@ 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 int win32_tmpfd_mode(int mode); DllExport FILE* win32_tmpfile(void); DllExport void win32_abort(void); DllExport int win32_fstat(int fd,Stat_t *sbufptr); -- Perl5 Master Repository