about summary refs log tree commit diff
path: root/converter/other/tifftopnm.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2009-09-05 19:20:43 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2009-09-05 19:20:43 +0000
commit73e355895808c26c4b8ffcae8464100554231792 (patch)
treefde92d84ca2a7f4d86c637b5b4616cf52f67b05f /converter/other/tifftopnm.c
parent5cd3c91e72481a3328ef439f075e6f22131d9cdf (diff)
downloadnetpbm-mirror-73e355895808c26c4b8ffcae8464100554231792.tar.gz
netpbm-mirror-73e355895808c26c4b8ffcae8464100554231792.tar.xz
netpbm-mirror-73e355895808c26c4b8ffcae8464100554231792.zip
Use new pm_fork(), pm_waitpidSimple(), work on systems without fork
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@984 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/tifftopnm.c')
-rw-r--r--converter/other/tifftopnm.c69
1 files changed, 31 insertions, 38 deletions
diff --git a/converter/other/tifftopnm.c b/converter/other/tifftopnm.c
index 611e1674..1cf869fb 100644
--- a/converter/other/tifftopnm.c
+++ b/converter/other/tifftopnm.c
@@ -52,7 +52,6 @@
 #include <assert.h>
 #include <string.h>
 #include <stdio.h>
-#include <sys/wait.h>
 
 #include "pm_c_util.h"
 #include "shhopt.h"
@@ -740,38 +739,34 @@ spawnWithInputPipe(const char *  const shellCmd,
         asprintfN(errorP, "Failed to create pipe for process input.  "
                   "Errno=%d (%s)", errno, strerror(errno));
     else {
-        int rc;
+        int iAmParent;
+        pid_t childPid;
 
-        rc = fork();
+        pm_fork(&iAmParent, &childPid, errorP);
 
-        if (rc < 0) {
-            asprintfN(errorP, "Failed to fork a process.  errno=%d (%s)",
-                      errno, strerror(errno));
-        } else if (rc == 0) {
-            /* This is the child */
-            int rc;
-            close(fd[PIPE_WRITE]);
-            close(STDIN_FILENO);
-            dup2(fd[PIPE_READ], STDIN_FILENO);
+        if (!*errorP) {
+            if (iAmParent) {
+                close(fd[PIPE_READ]);
 
-            rc = system(shellCmd);
-
-            exit(rc);
-        } else {
-            /* Parent */
-            pid_t const childPid = rc;
-
-            close(fd[PIPE_READ]);
+                *pidP   = childPid;
+                *pipePP = fdopen(fd[PIPE_WRITE], "w");
+                
+                if (*pipePP == NULL)
+                    asprintfN(errorP,"Unable to create stream from pipe.  "
+                              "fdopen() fails with errno=%d (%s)",
+                              errno, strerror(errno));
+                else
+                    *errorP = NULL;
+            } else {
+                int rc;
+                close(fd[PIPE_WRITE]);
+                close(STDIN_FILENO);
+                dup2(fd[PIPE_READ], STDIN_FILENO);
 
-            *pidP   = childPid;
-            *pipePP = fdopen(fd[PIPE_WRITE], "w");
+                rc = system(shellCmd);
 
-            if (*pipePP == NULL)
-                asprintfN(errorP,"Unable to create stream from pipe.  "
-                          "fdopen() fails with errno=%d (%s)",
-                          errno, strerror(errno));
-            else
-                *errorP = NULL;
+                exit(rc);
+            }
         }
     }
 }
@@ -974,12 +969,12 @@ pnmOut_init(FILE *         const imageoutFileP,
    data, pnmOut get 'cols' x 'rows' data, but its output file may be
    'rows x cols'.
 
-   Because the pnmOut object must be set up to receive flipped or not
-   flipped input, we have *flipOkP and *noflipOkP outputs that tell
-   Caller whether he has to flip or not.  In the unique case that
-   the TIFF matrix is already oriented the way the output PNM file needs
-   to be, flipping is idempotent, so both *flipOkP and *noflipOkP are
-   true.
+   Because we must set up the pnmOut object either to receive flipped or not
+   flipped input, we have *flipOkP and *noflipOkP outputs that tell Caller
+   whether he has to flip or not.  Note that Caller also influences which way
+   we set up pnmOut, with his 'flipIfNeeded' argument.  In the unique case
+   that the TIFF matrix is already oriented the way the output PNM file needs
+   to be, flipping is idempotent, so both *flipOkP and *noflipOkP are true.
 -----------------------------------------------------------------------------*/
     pnmOutP->imageoutFileP = imageoutFileP;
     pnmOutP->alphaFileP    = alphaFileP;
@@ -1041,14 +1036,12 @@ pnmOut_term(pnmOut * const pnmOutP,
                        "waiting for Pamflip to terminate");
 
         if (pnmOutP->imagePipeP) {
-            int status;
             fclose(pnmOutP->imagePipeP);
-            waitpid(pnmOutP->imageFlipPid, &status, 0);
+            pm_waitpidSimple(pnmOutP->imageFlipPid);
         }
         if (pnmOutP->alphaPipeP) {
-            int status;
             fclose(pnmOutP->alphaPipeP);
-            waitpid(pnmOutP->alphaFlipPid, &status, 0);
+            pm_waitpidSimple(pnmOutP->alphaFlipPid);
         }
     } else {
         if (pnmOutP->imageoutFileP)