integrate cfgperl changes#6174..6203 into mainline (first of several)
[p5sagit/p5-mst-13.2.git] / ext / IO / IO.xs
index e614cff..1b79cfd 100644 (file)
@@ -62,23 +62,28 @@ io_blocking(InputStream f, int block)
        /* 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;
+        * 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 */ 
@@ -357,8 +362,7 @@ setvbuf(handle, buf, type, size)
        int             type
        int             size
     CODE:
-/* Should check HAS_SETVBUF once Configure tests for that */
-#if defined(PERLIO_IS_STDIO) && defined(_IOFBF)
+#if defined(PERLIO_IS_STDIO) && defined(_IOFBF) && defined(HAS_SETVBUF)
        if (!handle)                    /* Try input stream. */
            handle = IoIFP(sv_2io(ST(0)));
        if (handle)
@@ -454,11 +458,4 @@ 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
 }