diff options
author | Tony Cook <tony@develop-help.com> | 2019-07-02 14:16:35 +1000 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2019-07-16 15:30:06 +1000 |
commit | ae73d7ec2329275a2dba4be24415743f884d9dfd (patch) | |
tree | 5707e77cade08fc8ea9f25855b6051c96a8de9fc /perlio.c | |
parent | dc9ac3ee562166ff93b09c2b5a63cc5c51748c7f (diff) | |
download | perl-ae73d7ec2329275a2dba4be24415743f884d9dfd.tar.gz |
(perl #134221) support append mode for open .. undef
Diffstat (limited to 'perlio.c')
-rw-r--r-- | perlio.c | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -1490,7 +1490,9 @@ PerlIO_openn(pTHX_ const char *layers, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args) { if (!f && narg == 1 && *args == &PL_sv_undef) { - if ((f = PerlIO_tmpfile())) { + int imode = PerlIOUnix_oflags(mode); + + if (imode != -1 && (f = PerlIO_tmpfile_flags(imode))) { if (!layers || !*layers) layers = Perl_PerlIO_context_layers(aTHX_ mode); if (layers && *layers) @@ -5043,6 +5045,15 @@ PerlIO_stdoutf(const char *fmt, ...) PerlIO * PerlIO_tmpfile(void) { + return PerlIO_tmpfile_flags(0); +} + +#define MKOSTEMP_MODES ( O_RDWR | O_CREAT | O_EXCL ) +#define MKOSTEMP_MODE_MASK ( O_ACCMODE | O_CREAT | O_EXCL | O_TRUNC ) + +PerlIO * +PerlIO_tmpfile_flags(int imode) +{ #ifndef WIN32 dTHX; #endif @@ -5057,27 +5068,32 @@ PerlIO_tmpfile(void) const char * const tmpdir = TAINTING_get ? NULL : PerlEnv_getenv("TMPDIR"); SV * sv = NULL; int old_umask = umask(0177); + imode &= ~MKOSTEMP_MODE_MASK; if (tmpdir && *tmpdir) { /* if TMPDIR is set and not empty, we try that first */ sv = newSVpv(tmpdir, 0); sv_catpv(sv, tempname + 4); - fd = Perl_my_mkstemp_cloexec(SvPVX(sv)); + fd = Perl_my_mkostemp_cloexec(SvPVX(sv), imode); } if (fd < 0) { SvREFCNT_dec(sv); sv = NULL; /* else we try /tmp */ - fd = Perl_my_mkstemp_cloexec(tempname); + fd = Perl_my_mkostemp_cloexec(tempname, imode); } if (fd < 0) { /* Try cwd */ sv = newSVpvs("."); sv_catpv(sv, tempname + 4); - fd = Perl_my_mkstemp_cloexec(SvPVX(sv)); + fd = Perl_my_mkostemp_cloexec(SvPVX(sv), imode); } umask(old_umask); if (fd >= 0) { - f = PerlIO_fdopen(fd, "w+"); + /* fdopen() with a numeric mode */ + char mode[8]; + int writing = 1; + (void)PerlIO_intmode2str(imode | MKOSTEMP_MODES, mode, &writing); + f = PerlIO_fdopen(fd, mode); if (f) PerlIOBase(f)->flags |= PERLIO_F_TEMP; PerlLIO_unlink(sv ? SvPVX_const(sv) : tempname); |