about summary refs log tree commit diff
path: root/lib/libpm.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-03-29 02:34:40 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-03-29 02:34:40 +0000
commitaf2df42c34088c6689bbe178a4317b55bce6b533 (patch)
tree9856b98231e5973fee4e2bd815e58e8cb056ab5f /lib/libpm.c
parent411f99f4445ea8b8fe85ff393e01dd6ef700cb48 (diff)
downloadnetpbm-mirror-af2df42c34088c6689bbe178a4317b55bce6b533.tar.gz
netpbm-mirror-af2df42c34088c6689bbe178a4317b55bce6b533.tar.xz
netpbm-mirror-af2df42c34088c6689bbe178a4317b55bce6b533.zip
Add pm_drain()
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@259 9d0c8265-081b-0410-96cb-a4ca84ce46f8
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;
+}