diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2003-06-03 09:51:59 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2003-06-03 09:51:59 +0000 |
commit | 2941a2e1ed23bc0518b5a6191536ac96286a18c1 (patch) | |
tree | 2770a44b45855a7cc1685884567f2c83da85ee6b /perlio.c | |
parent | f253e8355cf4011cc78385c0bd36c23d15d3d892 (diff) | |
download | perl-2941a2e1ed23bc0518b5a6191536ac96286a18c1.tar.gz |
Salvage parts of #19667.
p4raw-id: //depot/perl@19673
Diffstat (limited to 'perlio.c')
-rw-r--r-- | perlio.c | 66 |
1 files changed, 37 insertions, 29 deletions
@@ -4814,35 +4814,43 @@ PerlIO_stdoutf(const char *fmt, ...) PerlIO * PerlIO_tmpfile(void) { - /* - * I have no idea how portable mkstemp() is ... - */ -#if defined(WIN32) || !defined(HAVE_MKSTEMP) - dTHX; - PerlIO *f = NULL; - FILE *stdio = PerlSIO_tmpfile(); - if (stdio) { - if ((f = PerlIO_push(aTHX_(PerlIO_allocate(aTHX)), &PerlIO_stdio, "w+", Nullsv))) { - PerlIOStdio *s = PerlIOSelf(f, PerlIOStdio); - s->stdio = stdio; - } - } - return f; -#else - dTHX; - SV *sv = newSVpv("/tmp/PerlIO_XXXXXX", 0); - int fd = mkstemp(SvPVX(sv)); - PerlIO *f = NULL; - if (fd >= 0) { - f = PerlIO_fdopen(fd, "w+"); - if (f) { - PerlIOBase(f)->flags |= PERLIO_F_TEMP; - } - PerlLIO_unlink(SvPVX(sv)); - SvREFCNT_dec(sv); - } - return f; -#endif + dTHX; + PerlIO *f = NULL; + int fd = -1; +#ifdef WIN32 + fd = win32_tmpfd(); + if (fd >= 0) + f = PerlIO_fdopen(fd, "w+b"); +#else /* WIN32 */ +# ifdef HAS_MKSTEMP + SV *sv = newSVpv("/tmp/PerlIO_XXXXXX", 0); + + /* + * I have no idea how portable mkstemp() is ... NI-S + */ + fd = mkstemp(SvPVX(sv)); + if (fd >= 0) { + f = PerlIO_fdopen(fd, "w+"); + if (f) + PerlIOBase(f)->flags |= PERLIO_F_TEMP; + PerlLIO_unlink(SvPVX(sv)); + SvREFCNT_dec(sv); + } +# else /* !HAS_MKSTEMP, fallback to stdio tmpfile(). */ + FILE *stdio = PerlSIO_tmpfile(); + + if (stdio) { + if ((f = PerlIO_push(aTHX_(PerlIO_allocate(aTHX)), + &PerlIO_stdio, "w+", Nullsv))) { + PerlIOStdio *s = PerlIOSelf(f, PerlIOStdio); + + if (s) + s->stdio = stdio; + } + } +# endif /* else HAS_MKSTEMP */ +#endif /* else WIN32 */ + return f; } #undef HAS_FSETPOS |