fix up B modules for PL_* changes
[p5sagit/p5-mst-13.2.git] / ext / IO / IO.xs
index a6eb075..a434cca 100644 (file)
@@ -7,7 +7,14 @@
 #  include <unistd.h>
 #endif
 #ifdef I_FCNTL
+#if defined(__GNUC__) && defined(__cplusplus) && defined(WIN32)
+#define _NO_OLDNAMES
+#endif 
 #  include <fcntl.h>
+#if defined(__GNUC__) && defined(__cplusplus) && defined(WIN32)
+#undef _NO_OLDNAMES
+#endif 
+
 #endif
 
 #ifdef PerlIO
@@ -22,17 +29,14 @@ typedef FILE * OutputStream;
 #endif
 
 static int
-not_here(s)
-char *s;
+not_here(char *s)
 {
     croak("%s not implemented on this architecture", s);
     return -1;
 }
 
 static bool
-constant(name, pval)
-char *name;
-IV *pval;
+constant(char *name, IV *pval)
 {
     switch (*name) {
     case '_':
@@ -97,7 +101,7 @@ fgetpos(handle)
            ST(0) = sv_2mortal(newSVpv((char*)&pos, sizeof(Fpos_t)));
        }
        else {
-           ST(0) = &sv_undef;
+           ST(0) = &PL_sv_undef;
            errno = EINVAL;
        }
 
@@ -106,11 +110,12 @@ fsetpos(handle, pos)
        InputStream     handle
        SV *            pos
     CODE:
-       if (handle)
+       char *p;
+       if (handle && (p = SvPVx(pos, PL_na)) && PL_na == sizeof(Fpos_t))
 #ifdef PerlIO
-           RETVAL = PerlIO_setpos(handle, (Fpos_t*)SvPVX(pos));
+           RETVAL = PerlIO_setpos(handle, (Fpos_t*)p);
 #else
-           RETVAL = fsetpos(handle, (Fpos_t*)SvPVX(pos));
+           RETVAL = fsetpos(handle, (Fpos_t*)p);
 #endif
        else {
            RETVAL = -1;
@@ -121,17 +126,29 @@ fsetpos(handle, pos)
 
 MODULE = IO    PACKAGE = IO::File      PREFIX = f
 
-OutputStream
+SV *
 new_tmpfile(packname = "IO::File")
     char *             packname
+    PREINIT:
+       OutputStream fp;
+       GV *gv;
     CODE:
 #ifdef PerlIO
-       RETVAL = PerlIO_tmpfile();
+       fp = PerlIO_tmpfile();
 #else
-       RETVAL = tmpfile();
+       fp = tmpfile();
 #endif
-    OUTPUT:
-       RETVAL
+       gv = (GV*)SvREFCNT_inc(newGVgen(packname));
+       hv_delete(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv), G_DISCARD);
+       if (do_open(gv, "+>&", 3, FALSE, 0, 0, fp)) {
+           ST(0) = sv_2mortal(newRV((SV*)gv));
+           sv_bless(ST(0), gv_stashpv(packname, TRUE));
+           SvREFCNT_dec(gv);   /* undo increment in newRV() */
+       }
+       else {
+           ST(0) = &PL_sv_undef;
+           SvREFCNT_dec(gv);
+       }
 
 MODULE = IO    PACKAGE = IO::Handle    PREFIX = f
 
@@ -143,7 +160,7 @@ constant(name)
        if (constant(name, &i))
            ST(0) = sv_2mortal(newSViv(i));
        else
-           ST(0) = &sv_undef;
+           ST(0) = &PL_sv_undef;
 
 int
 ungetc(handle, c)
@@ -256,8 +273,10 @@ setvbuf(handle, buf, type, size)
        int             type
        int             size
     CODE:
-#ifdef PERLIO_IS_STDIO
-#ifdef _IOFBF   /* Should be HAS_SETVBUF once Configure tests for that */
+/* Should check HAS_SETVBUF once Configure tests for that */
+#if defined(PERLIO_IS_STDIO) && defined(_IOFBF)
+       if (!handle)                    /* Try input stream. */
+           handle = IoIFP(sv_2io(ST(0)));
        if (handle)
            RETVAL = setvbuf(handle, buf, type, size);
        else {
@@ -265,10 +284,7 @@ setvbuf(handle, buf, type, size)
            errno = EINVAL;
        }
 #else
-           RETVAL = (SysRet) not_here("IO::Handle::setvbuf");
-#endif /* _IOFBF */
-#else
-           not_here("IO::Handle::setvbuf");
+       RETVAL = (SysRet) not_here("IO::Handle::setvbuf");
 #endif
     OUTPUT:
        RETVAL