about summary refs log tree commit diff
path: root/converter/ppm
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-10-07 19:40:20 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-10-07 19:40:20 +0000
commit7058c14b1e8ae4184d8bbbd29df725abf38371b9 (patch)
tree4a9806985e13bc1f29686fa16e42868be2105fbb /converter/ppm
parente6563555c0e86e2d28cae402b35e1951a686a9a8 (diff)
downloadnetpbm-mirror-7058c14b1e8ae4184d8bbbd29df725abf38371b9.tar.gz
netpbm-mirror-7058c14b1e8ae4184d8bbbd29df725abf38371b9.tar.xz
netpbm-mirror-7058c14b1e8ae4184d8bbbd29df725abf38371b9.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3394 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/ppm')
-rw-r--r--converter/ppm/xvminitoppm.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/converter/ppm/xvminitoppm.c b/converter/ppm/xvminitoppm.c
index 0da1515e..34a0f9b5 100644
--- a/converter/ppm/xvminitoppm.c
+++ b/converter/ppm/xvminitoppm.c
@@ -13,12 +13,13 @@
 #include <assert.h>
 #include <string.h>
 #include <errno.h>
+#include <stdbool.h>
 
 #include "pm_c_util.h"
 #include "nstring.h"
+#include "pm.h"
 #include "ppm.h"
 
-#define BUFSIZE 256
 
 
 typedef struct xvPalette {
@@ -53,25 +54,6 @@ parseCommandLine(int const argc,
 
 
 static void
-getLine(FILE * const ifP,
-        char * const buf,
-        size_t const size) {
-
-    char * rc;
-
-    rc = fgets(buf, size, ifP);
-    if (rc == NULL) {
-        if (ferror(ifP))
-            pm_error("read error.  fgets() failed, errno=%d (%s)",
-                     errno, strerror(errno));
-        else
-            pm_error("unexpected EOF");
-    }
-}
-
-
-
-static void
 makeXvPalette(xvPalette * const xvPaletteP) {
 
     unsigned int paletteIndex;
@@ -102,36 +84,54 @@ readXvHeader(FILE *         const ifP,
              unsigned int * const rowsP,
              unsigned int * const maxvalP) {
 
-    char buf[256];
+    char * buf;
+    size_t bufferSz;
+    int eof;
+    size_t lineLen;
     unsigned int cols, rows, maxval;
     int rc;
     bool endOfComments;
 
-    getLine(ifP, buf, sizeof(buf));
+    buf = NULL;   /* initial value */
+    bufferSz = 0; /* initial value */
+
+    pm_getline(ifP, &buf, &bufferSz, &eof, &lineLen);
+    if (eof)
+        pm_error("Unexpected EOF");
 
     if (!strneq(buf, "P7 332", 6))
         pm_error("Input is not a XV thumbnail picture.  It does not "
                  "begin with the characters 'P7 332'.");
 
-    endOfComments = FALSE;
-    while (!endOfComments) {
-        getLine(ifP, buf, sizeof(buf));
+    for (endOfComments = false; !endOfComments; ) {
+        int eof;
+        size_t lineLen;
+        pm_getline(ifP, &buf, &bufferSz, &eof, &lineLen);
+        if (eof)
+            pm_error("Unexpected EOF");
         if (strneq(buf, "#END_OF_COMMENTS", 16))
-            endOfComments = TRUE;
+            endOfComments = true;
         else if (strneq(buf, "#BUILTIN", 8))
             pm_error("This program does not know how to "
                      "convert builtin XV thumbnail pictures");
     }
-    getLine(ifP, buf, sizeof(buf));
+    pm_getline(ifP, &buf, &bufferSz, &eof, &lineLen);
+    if (eof)
+        pm_error("Unexpected EOF");
+
     rc = sscanf(buf, "%u %u %u", &cols, &rows, &maxval);
     if (rc != 3)
         pm_error("error parsing dimension info '%s'.  "
                  "It does not consist of 3 decimal numbers.", buf);
     if (maxval != 255)
         pm_error("bogus XV thumbnail maxval %u.  Should be 255", maxval);
+
     *colsP = cols;
     *rowsP = rows;
     *maxvalP = maxval;
+
+    if (buf)
+        free(buf);
 }