#19655, #19418; File::Temp no more used internally.
Some parts of these will be salvaged later.
p4raw-id: //depot/perl@19670
ext/PerlIO/t/encoding.t See if PerlIO encoding conversion works
ext/PerlIO/t/fail.t See if bad layers fail
ext/PerlIO/t/fallback.t See if PerlIO fallbacks work
-ext/PerlIO/t/open.t See if PerlIO certain special opens work
ext/PerlIO/t/scalar.t See if PerlIO::scalar works
ext/PerlIO/t/via.t See if PerlIO::via works
ext/PerlIO/via/Makefile.PL PerlIO layer for layers in perl
Adp |void |sv_nounlocking |SV *
Adp |int |nothreadhook
-p |PerlIO*|my_tmpfp
-
END_EXTERN_C
#if defined(PERL_IN_DOOP_C) || defined(PERL_DECL_PROT)
#define sv_nolocking Perl_sv_nolocking
#define sv_nounlocking Perl_sv_nounlocking
#define nothreadhook Perl_nothreadhook
-#ifdef PERL_CORE
-#define my_tmpfp Perl_my_tmpfp
-#endif
#if defined(PERL_IN_DOOP_C) || defined(PERL_DECL_PROT)
#ifdef PERL_CORE
#define do_trans_simple S_do_trans_simple
#define sv_nolocking(a) Perl_sv_nolocking(aTHX_ a)
#define sv_nounlocking(a) Perl_sv_nounlocking(aTHX_ a)
#define nothreadhook() Perl_nothreadhook(aTHX)
-#ifdef PERL_CORE
-#define my_tmpfp() Perl_my_tmpfp(aTHX)
-#endif
#if defined(PERL_IN_DOOP_C) || defined(PERL_DECL_PROT)
#ifdef PERL_CORE
#define do_trans_simple(a) S_do_trans_simple(aTHX_ a)
ST(0) = (SV*)XSANY.any_ptr;
XSRETURN(1);
}
-
-/* XXX this belongs in doio.c, not here */
-PerlIO*
-Perl_my_tmpfp(pTHX)
-{
- PerlIO *f = NULL;
- int fd = -1;
-#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)
- 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;
- }
- }
-# else /* !WIN32 && HAS_MKSTEMP */
- SV *sv = newSVpv("/tmp/PerlIO_XXXXXX", 0);
-
- if (sv) {
- fd = mkstemp(SvPVX(sv));
- if (fd >= 0) {
- f = PerlIO_fdopen(fd, "w+");
- if (f) {
- PerlLIO_unlink(SvPVX(sv));
- SvREFCNT_dec(sv);
- }
- }
- }
-# 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);
-
- if (!gv) {
- ENTER;
- Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT,
- newSVpvn("File::Temp", 10), Nullsv, Nullsv, Nullsv);
- gv = gv_fetchpv("File::Temp::tempfile", FALSE, SVt_PVCV);
- GvIMPORTED_CV_on(gv);
- LEAVE;
- }
- if (gv && GvCV(gv)) {
- dSP;
- ENTER;
- SAVETMPS;
- PUSHMARK(SP);
- PUTBACK;
- if (call_sv((SV*)GvCV(gv), G_SCALAR)) {
- GV *gv = (GV*)SvRV(newSVsv(*PL_stack_sp--));
-
- if (gv) {
- IO *io = GvIO(gv);
-
- if (io) {
- fd = PerlIO_fileno(IoIFP(io));
- if (fd >= 0)
- f = PerlIO_fdopen(fd, "w+");
- }
- }
- }
- SPAGAIN;
- PUTBACK;
- FREETMPS;
- LEAVE;
- }
-# endif
-#endif
-
- return f;
-}
PerlIO *
PerlIO_tmpfile(void)
{
- dTHX;
- PerlIO *f = Perl_my_tmpfp(aTHX);
-
- if (f)
- PerlIOBase(f)->flags |= PERLIO_F_TEMP;
-
- return f;
+ /*
+ * 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
}
#undef HAS_FSETPOS
return result;
}
#endif
+
+
+
+
+
+
+
+
open(TMP, "+>", undef) or die ...
-opens a filehandle to an anonymous temporary file. Also using "+<"
-works for symmetry, but you really should consider writing something
-to the temporary file first. You will need to seek() to do the
-reading. Starting from Perl 5.8.1 the temporary files are created
-using the File::Temp module for greater portability, in Perl 5.8.0 the
-mkstemp() system call (which has known bugs in some platforms) was used.
+opens a filehandle to an anonymous temporary file.
File handles can be opened to "in memory" files held in Perl scalars via:
PERL_CALLCONV void Perl_sv_nounlocking(pTHX_ SV *);
PERL_CALLCONV int Perl_nothreadhook(pTHX);
-PERL_CALLCONV PerlIO* Perl_my_tmpfp(pTHX);
-
END_EXTERN_C
#if defined(PERL_IN_DOOP_C) || defined(PERL_DECL_PROT)
return;
}
-DllExport int
-win32_tmpfd(void)
+DllExport FILE*
+win32_tmpfile(void)
{
dTHX;
char prefix[MAX_PATH+1];
#endif
DEBUG_p(PerlIO_printf(Perl_debug_log,
"Created tmpfile=%s\n",filename));
- return fd;
+ return fdopen(fd, "w+b");
}
}
}
}
- return -1;
-}
-
-DllExport FILE*
-win32_tmpfile(void)
-{
- int fd = win32_tmpfd();
- if (fd >= 0)
- return win32_fdopen(fd, "w+b");
return NULL;
}
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);