about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-11-28 18:07:05 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-11-28 18:07:05 +0000
commitbd509425fa6d6caa5af70604b752fb46139c1c38 (patch)
treea27a4393772a85b64c409f37da192005423f19ef /lib
parenteb31c65537daa22720c05d821d9a7f9ff0869d8e (diff)
downloadnetpbm-mirror-bd509425fa6d6caa5af70604b752fb46139c1c38.tar.gz
netpbm-mirror-bd509425fa6d6caa5af70604b752fb46139c1c38.tar.xz
netpbm-mirror-bd509425fa6d6caa5af70604b752fb46139c1c38.zip
Drop infeasible pm_feed_from_filestream, add pm_feed_from_file, pm_accept_to_file
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4791 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/libsystem.c67
-rw-r--r--lib/pm_system.h8
2 files changed, 70 insertions, 5 deletions
diff --git a/lib/libsystem.c b/lib/libsystem.c
index f5c73f1b..3c23e0c0 100644
--- a/lib/libsystem.c
+++ b/lib/libsystem.c
@@ -767,18 +767,21 @@ pm_accept_to_memory(int             const pipeToSuckFd,
 
 
 void
-pm_feed_from_filestream(int    const pipeToFeedFd,
-                        void * const feederParm) {
+pm_feed_from_file(int    const pipeToFeedFd,
+                  void * const feederParm) {
 
-    FILE * const inFileP  = feederParm;
+    const char * const inFileNm = feederParm;
 
     size_t const bufferSz = 64*1024;
 
     FILE * const outFileP = fdopen(pipeToFeedFd, "w");
 
+    FILE * inFileP;
     unsigned char * buffer;
     bool eof;
 
+    inFileP = pm_openr(inFileNm);
+
     MALLOCARRAY(buffer, bufferSz);
 
     if (!buffer)
@@ -803,6 +806,7 @@ pm_feed_from_filestream(int    const pipeToFeedFd,
             eof = true;
     }
 
+    pm_close(inFileP);
     fclose(outFileP);
 
     free(buffer);
@@ -811,6 +815,63 @@ pm_feed_from_filestream(int    const pipeToFeedFd,
 
 
 void
+pm_accept_to_file(int             const pipeToSuckFd,
+                  void *          const accepterParm ) {
+
+    const char * const outFileNm = accepterParm;
+
+    size_t const bufferSz = 64*1024;
+
+    FILE * const inFileP = fdopen(pipeToSuckFd, "r");
+
+    FILE * outFileP;
+    unsigned char * buffer;
+    bool eof;
+
+    outFileP = pm_openw(outFileNm);
+
+    MALLOCARRAY(buffer, bufferSz);
+
+    if (!buffer)
+        pm_error("Failed to allocate %u bytes for I/O buffer",
+                 (unsigned) bufferSz);
+
+    for (eof = false; !eof; ) {
+        size_t byteCtRead;
+
+        byteCtRead = fread(buffer, 1, bufferSz, inFileP);
+
+        if (ferror(inFileP))
+            pm_error("Error reading Standard Output accepter pipe.  "
+                     "errno=%d (%s)",
+                     errno, strerror(errno));
+
+        if (byteCtRead > 0) {
+            fwrite(buffer, 1, byteCtRead, outFileP);
+
+            if (ferror(outFileP))
+                pm_error("Error writing to file.  errno=%d (%s)",
+                         errno, strerror(errno));
+        } else
+            eof = true;
+    }
+
+    pm_close(outFileP);
+    fclose(inFileP);
+
+    free(buffer);
+}
+
+
+
+/* Note that pm_feed_from_filestream is not possible because Standard Input is
+   feed by a child process and we can't properly pass a FILE * to a child
+   process.
+*/
+
+
+
+void
 pm_accept_to_filestream(int             const pipeToSuckFd,
                         void *          const accepterParm ) {
 
diff --git a/lib/pm_system.h b/lib/pm_system.h
index f6f87451..5cfc50cf 100644
--- a/lib/pm_system.h
+++ b/lib/pm_system.h
@@ -102,8 +102,12 @@ pm_accept_to_memory(int    const pipetosuckFd,
                     void * const accepterParm);
 
 void
-pm_feed_from_filestream(int    const pipeToFeedFd,
-                        void * const feederParm);
+pm_feed_from_file(int    const pipeToFeedFd,
+                  void * const feederParm);
+
+void
+pm_accept_to_file(int    const pipetosuckFd,
+                  void * const accepterParm);
 
 void
 pm_accept_to_filestream(int    const pipetosuckFd,