about summary refs log tree commit diff
path: root/lib/libpm.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libpm.c')
-rw-r--r--lib/libpm.c29
1 files changed, 29 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;
+}