Author: infinoid
Date: Tue Mar 25 15:23:25 2008
New Revision: 26548

Modified:
   trunk/include/parrot/io.h
   trunk/src/io/io.c
   trunk/src/io/io_unix.c

Log:
[io] Apply patch similar in spirit to RT #51988
Hopefully this will resolve warnings on win32/msvc.  I'm pretty sure it won't
affect any other platform.


Modified: trunk/include/parrot/io.h
==============================================================================
--- trunk/include/parrot/io.h   (original)
+++ trunk/include/parrot/io.h   Tue Mar 25 15:23:25 2008
@@ -123,6 +123,12 @@
 #define PIO_DOWNLAYER(x)   (x)->down
 #define PIO_UPLAYER(x)     (x)->up
 
+#ifdef _MSC_VER
+/* Win32/MSVC has a deprecation warning about dup() in favor of _dup(). */
+#  define Parrot_dup(x) (PIOHANDLE)_dup((int)(x))
+#else /* !_MSC_VER */
+#  define Parrot_dup(x) (PIOHANDLE)dup((int)(x))
+#endif /* _MSC_VER */
 
 /* Others to come */
 #ifdef PIO_OS_UNIX

Modified: trunk/src/io/io.c
==============================================================================
--- trunk/src/io/io.c   (original)
+++ trunk/src/io/io.c   Tue Mar 25 15:23:25 2008
@@ -177,7 +177,7 @@
 PIO_dup(PARROT_INTERP, ARGIN(PMC *pmc))
 {
     ParrotIO * const io   = PMC_data_typed(pmc, ParrotIO *);
-    const PIOHANDLE newfd = dup(io->fd);
+    const PIOHANDLE newfd = Parrot_dup(io->fd);
     ParrotIOLayer * layer = (ParrotIOLayer *)PMC_struct_val(pmc);
 
     ParrotIO * newio;
@@ -186,12 +186,12 @@
         layer = interp->piodata->default_stack;
     }
 
-    if (newfd == -1) {
+    if (newfd == (PIOHANDLE)-1) {
         real_exception(interp, NULL, 1, "could not dup an fd");
     }
 
     newio = PIO_fdopen_down(interp, layer, newfd, io->flags);
-    /* io could be null here but we still have to
+    /* io could be null here but we still have
      * to create a PMC for the caller, no PMCNULL here
      * as that would cause an exception upon access.
      */

Modified: trunk/src/io/io_unix.c
==============================================================================
--- trunk/src/io/io_unix.c      (original)
+++ trunk/src/io/io_unix.c      Tue Mar 25 15:23:25 2008
@@ -1141,7 +1141,7 @@
             /* the other end is writing - we read from the pipe */
             close(STDIN_FILENO);
             close(fds[1]);
-            if (dup(fds[0]) != STDIN_FILENO) {
+            if (Parrot_dup(fds[0]) != STDIN_FILENO) {
                 exit(EXIT_SUCCESS);
             }
         }
@@ -1150,8 +1150,9 @@
             close(STDIN_FILENO);
             close(STDOUT_FILENO);
             close(STDERR_FILENO);
-            if (dup(fds[0]) != STDIN_FILENO || dup(fds[1]) != STDOUT_FILENO
-                    || dup(fds[1]) != STDERR_FILENO)
+            if (Parrot_dup(fds[0]) != STDIN_FILENO
+             || Parrot_dup(fds[1]) != STDOUT_FILENO
+             || Parrot_dup(fds[1]) != STDERR_FILENO)
             {
                 exit(EXIT_SUCCESS);
             }

Reply via email to