Add new step to run_byacc which:
[p5sagit/p5-mst-13.2.git] / ext / IO / IO.xs
index e5ce83d..8bdc133 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;
@@ -59,29 +65,34 @@ io_blocking(InputStream f, int block)
     if (RETVAL >= 0) {
        int mode = RETVAL;
 #ifdef O_NONBLOCK
-       /* POSIX style */ 
+       /* POSIX style */
 #if defined(O_NDELAY) && O_NDELAY != O_NONBLOCK
-       /* Ooops has O_NDELAY too - make sure we don't 
-        * get SysV behaviour by mistake
-        */
-       RETVAL = RETVAL & O_NONBLOCK ? 0 : 1;
-
-       if ((mode & O_NDELAY) || ((block == 0) && !(mode & O_NONBLOCK))) {
-           int ret;
-           mode = (mode & ~O_NDELAY) | O_NONBLOCK;
-           ret = fcntl(PerlIO_fileno(f),F_SETFL,mode);
-           if(ret < 0)
-               RETVAL = ret;
-       }
-       else if ((mode & O_NDELAY) || ((block > 0) && (mode & O_NONBLOCK))) {
-           int ret;
-           mode &= ~(O_NONBLOCK | O_NDELAY);
-           ret = fcntl(PerlIO_fileno(f),F_SETFL,mode);
-           if(ret < 0)
-               RETVAL = ret;
+       /* Ooops has O_NDELAY too - make sure we don't
+        * get SysV behaviour by mistake. */
+
+       /* E.g. In UNICOS and UNICOS/mk a F_GETFL returns an O_NDELAY
+        * after a successful F_SETFL of an O_NONBLOCK. */
+       RETVAL = RETVAL & (O_NONBLOCK | O_NDELAY) ? 0 : 1;
+
+       if (block >= 0) {
+           if ((mode & O_NDELAY) || ((block == 0) && !(mode & O_NONBLOCK))) {
+               int ret;
+               mode = (mode & ~O_NDELAY) | O_NONBLOCK;
+               ret = fcntl(PerlIO_fileno(f),F_SETFL,mode);
+               if(ret < 0)
+                   RETVAL = ret;
+           }
+           else
+              if ((mode & O_NDELAY) || ((block > 0) && (mode & O_NONBLOCK))) {
+               int ret;
+               mode &= ~(O_NONBLOCK | O_NDELAY);
+               ret = fcntl(PerlIO_fileno(f),F_SETFL,mode);
+               if(ret < 0)
+                   RETVAL = ret;
+              }
        }
 #else
-       /* Standard POSIX */ 
+       /* Standard POSIX */
        RETVAL = RETVAL & O_NONBLOCK ? 0 : 1;
 
        if ((block == 0) && !(mode & O_NONBLOCK)) {
@@ -98,11 +109,11 @@ io_blocking(InputStream f, int block)
            if(ret < 0)
                RETVAL = ret;
         }
-#endif 
+#endif
 #else
        /* Not POSIX - better have O_NDELAY or we can't cope.
         * for BSD-ish machines this is an acceptable alternative
-        * for SysV we can't tell "would block" from EOF but that is 
+        * for SysV we can't tell "would block" from EOF but that is
         * the way SysV is...
         */
        RETVAL = RETVAL & O_NDELAY ? 0 : 1;
@@ -131,18 +142,23 @@ io_blocking(InputStream f, int block)
 
 MODULE = IO    PACKAGE = IO::Seekable  PREFIX = f
 
-SV *
+void
 fgetpos(handle)
        InputStream     handle
     CODE:
        if (handle) {
-           Fpos_t pos;
 #ifdef PerlIO
-           PerlIO_getpos(handle, &pos);
+           ST(0) = sv_2mortal(newSV(0));
+           if (PerlIO_getpos(handle, ST(0)) != 0) {
+               ST(0) = &PL_sv_undef;
+           }
 #else
-           fgetpos(handle, &pos);
+           if (fgetpos(handle, &pos)) {
+               ST(0) = &PL_sv_undef;
+           } else {
+               ST(0) = sv_2mortal(newSVpv((char*)&pos, sizeof(Fpos_t)));
+           }
 #endif
-           ST(0) = sv_2mortal(newSVpv((char*)&pos, sizeof(Fpos_t)));
        }
        else {
            ST(0) = &PL_sv_undef;
@@ -154,14 +170,21 @@ fsetpos(handle, pos)
        InputStream     handle
        SV *            pos
     CODE:
-        char *p;
-       STRLEN len;
-       if (handle && (p = SvPV(pos,len)) && len == sizeof(Fpos_t))
+       if (handle) {
 #ifdef PerlIO
-           RETVAL = PerlIO_setpos(handle, (Fpos_t*)p);
+           RETVAL = PerlIO_setpos(handle, pos);
 #else
-           RETVAL = fsetpos(handle, (Fpos_t*)p);
+           char *p;
+           STRLEN len;
+           if ((p = SvPV(pos,len)) && len == sizeof(Fpos_t)) {
+               RETVAL = fsetpos(handle, (Fpos_t*)p);
+           }
+           else {
+               RETVAL = -1;
+               errno = EINVAL;
+           }
 #endif
+       }
        else {
            RETVAL = -1;
            errno = EINVAL;
@@ -171,7 +194,7 @@ fsetpos(handle, pos)
 
 MODULE = IO    PACKAGE = IO::File      PREFIX = f
 
-SV *
+void
 new_tmpfile(packname = "IO::File")
     char *             packname
     PREINIT:
@@ -197,7 +220,7 @@ new_tmpfile(packname = "IO::File")
 
 MODULE = IO    PACKAGE = IO::Poll
 
-void   
+void
 _poll(timeout,...)
        int timeout;
 PPCODE:
@@ -245,7 +268,6 @@ CODE:
 
 MODULE = IO    PACKAGE = IO::Handle    PREFIX = f
 
-
 int
 ungetc(handle, c)
        InputStream     handle
@@ -391,6 +413,35 @@ 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
+       if (ioctl(fd, SIOCATMARK, &flag) != 0)
+        XSRETURN_UNDEF;
+#   else
+       not_here("IO::Socket::atmark");
+#   endif
+       RETVAL = flag;
+     }
+#endif
+   }
+   OUTPUT:
+     RETVAL
+
 BOOT:
 {
     HV *stash;
@@ -453,11 +504,5 @@ BOOT:
 #ifdef SEEK_END
         newCONSTSUB(stash,"SEEK_END", newSViv(SEEK_END));
 #endif
-    /*
-     * constant subs for IO
-     */
-    stash = gv_stashpvn("IO", 2, TRUE);
-#ifdef EINPROGRESS
-        newCONSTSUB(stash,"EINPROGRESS", newSViv(EINPROGRESS));
-#endif
 }
+