patch to ext/IO/lib/IO/Socket/INET.pm fixes Bug ID (20010803.022)
[p5sagit/p5-mst-13.2.git] / ext / IO / IO.xs
index 13b198c..6741905 100644 (file)
 #  include <fcntl.h>
 #endif
 
+#ifndef SIOCATMARK
+#   ifdef I_SYS_SOCKIO
+#       include <sys/sockio.h>
+#   endif
+#endif
+
 #ifdef PerlIO
 typedef int SysRet;
 typedef PerlIO * InputStream;
@@ -136,7 +142,7 @@ io_blocking(InputStream f, int block)
 
 MODULE = IO    PACKAGE = IO::Seekable  PREFIX = f
 
-SV *
+void
 fgetpos(handle)
        InputStream     handle
     CODE:
@@ -188,7 +194,7 @@ fsetpos(handle, pos)
 
 MODULE = IO    PACKAGE = IO::File      PREFIX = f
 
-SV *
+void
 new_tmpfile(packname = "IO::File")
     char *             packname
     PREINIT:
@@ -262,7 +268,6 @@ CODE:
 
 MODULE = IO    PACKAGE = IO::Handle    PREFIX = f
 
-
 int
 ungetc(handle, c)
        InputStream     handle
@@ -356,33 +361,47 @@ fflush(handle)
        RETVAL
 
 void
-setbuf(handle, buf)
+setbuf(handle, ...)
        OutputStream    handle
-       char *          buf = SvPOK(ST(1)) ? sv_grow(ST(1), BUFSIZ) : 0;
     CODE:
        if (handle)
 #ifdef PERLIO_IS_STDIO
+        {
+           char *buf = items == 2 && SvPOK(ST(1)) ?
+             sv_grow(ST(1), BUFSIZ) : 0;
            setbuf(handle, buf);
+       }
 #else
            not_here("IO::Handle::setbuf");
 #endif
 
 SysRet
-setvbuf(handle, buf, type, size)
-       OutputStream    handle
-       char *          buf = SvPOK(ST(1)) ? sv_grow(ST(1), SvIV(ST(3))) : 0;
-       int             type
-       int             size
+setvbuf(...)
     CODE:
+       if (items != 4)
+            Perl_croak(aTHX_ "Usage: IO::Handle::setvbuf(handle, buf, type, size)");
 #if defined(PERLIO_IS_STDIO) && defined(_IOFBF) && defined(HAS_SETVBUF)
+    {
+        OutputStream   handle = 0;
+       char *          buf = SvPOK(ST(1)) ? sv_grow(ST(1), SvIV(ST(3))) : 0;
+       int             type;
+       int             size;
+
+       if (items == 4) {
+           handle = IoOFP(sv_2io(ST(0)));
+           buf    = SvPOK(ST(1)) ? sv_grow(ST(1), SvIV(ST(3))) : 0;
+           type   = (int)SvIV(ST(2));
+           size   = (int)SvIV(ST(3));
+       }
        if (!handle)                    /* Try input stream. */
            handle = IoIFP(sv_2io(ST(0)));
-       if (handle)
+       if (items == 4 && handle)
            RETVAL = setvbuf(handle, buf, type, size);
        else {
            RETVAL = -1;
            errno = EINVAL;
        }
+    }
 #else
        RETVAL = (SysRet) not_here("IO::Handle::setvbuf");
 #endif
@@ -408,6 +427,39 @@ fsync(handle)
        RETVAL
 
 
+MODULE = IO    PACKAGE = IO::Socket
+
+SysRet
+sockatmark (sock)
+   InputStream sock
+   PROTOTYPE: $
+   PREINIT:
+     int fd;
+   CODE:
+   {
+     fd = PerlIO_fileno(sock);
+#ifdef HAS_SOCKATMARK
+     RETVAL = sockatmark(fd);
+#else
+     {
+       int flag = 0;
+#   ifdef SIOCATMARK
+       #ifdef NETWARE
+       if (ioctl(fd, SIOCATMARK, (void*)&flag) != 0)
+       #else
+          if (ioctl(fd, SIOCATMARK, &flag) != 0)
+       #endif
+        XSRETURN_UNDEF;
+#   else
+       not_here("IO::Socket::atmark");
+#   endif
+       RETVAL = flag;
+     }
+#endif
+   }
+   OUTPUT:
+     RETVAL
+
 BOOT:
 {
     HV *stash;
@@ -471,3 +523,4 @@ BOOT:
         newCONSTSUB(stash,"SEEK_END", newSViv(SEEK_END));
 #endif
 }
+