about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--lib/libpm.c29
-rw-r--r--lib/pm.h5
2 files changed, 34 insertions, 0 deletions
diff --git a/lib/libpm.c b/lib/libpm.c
index f36b7a50..88b790e6 100644
--- a/lib/libpm.c
+++ b/lib/libpm.c
@@ -1662,3 +1662,32 @@ pm_check(FILE *               const file,
 
 
 
+void
+pm_drain(FILE * const fileP,
+         uint   const limit,
+         uint * const bytesReadP) {
+/*----------------------------------------------------------------------------
+  Read bytes from *fileP until EOF and return as *bytesReadP how many there
+  were.
+
+  But don't read any more than 'limit'.
+
+  This is a good thing to call after reading an input file to be sure you
+  didn't leave some input behind, which could mean you didn't properly
+  interpret the file.
+-----------------------------------------------------------------------------*/
+    uint bytesRead;
+    bool eof;
+
+    for (bytesRead = 0, eof = false; !eof && bytesRead < 4096;) {
+
+        int rc;
+
+        rc = fgetc(fileP);
+
+        eof = (rc == EOF);
+        if (!eof)
+            ++bytesRead;
+    }
+    *bytesReadP = bytesRead;
+}
diff --git a/lib/pm.h b/lib/pm.h
index 8265c9ea..232fc363 100644
--- a/lib/pm.h
+++ b/lib/pm.h
@@ -345,6 +345,11 @@ pm_check(FILE *               const file,
          pm_filepos           const need_raster_size,
          enum pm_check_code * const retval_p);
 
+void
+pm_drain(FILE *         const fileP,
+         unsigned int   const limit,
+         unsigned int * const bytesReadP);
+
 char *
 pm_arg0toprogname(const char arg0[]);