about summary refs log tree commit diff
path: root/lib/pmfileio.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2009-04-25 21:11:42 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2009-04-25 21:11:42 +0000
commit46db732a13a90790b158da2a360b92bdcb894440 (patch)
treef7f1c5c835c4f21ccdf237c012d148e95e8255db /lib/pmfileio.c
parent5f81c5a08f2da9529a2e885df16df1c81bfac38d (diff)
downloadnetpbm-mirror-46db732a13a90790b158da2a360b92bdcb894440.tar.gz
netpbm-mirror-46db732a13a90790b158da2a360b92bdcb894440.tar.xz
netpbm-mirror-46db732a13a90790b158da2a360b92bdcb894440.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@884 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/pmfileio.c')
-rw-r--r--lib/pmfileio.c84
1 files changed, 26 insertions, 58 deletions
diff --git a/lib/pmfileio.c b/lib/pmfileio.c
index 8af085b7..585b0d0f 100644
--- a/lib/pmfileio.c
+++ b/lib/pmfileio.c
@@ -452,17 +452,26 @@ abortWithReadError(FILE * const ifP) {
 
 
 
-void
-pm_readchar(FILE * const ifP,
-            char * const cP) {
-    
+static unsigned char
+getcNofail(FILE * const ifP) {
+
     int c;
 
     c = getc(ifP);
+
     if (c == EOF)
         abortWithReadError(ifP);
 
-    *cP = c;
+    return (unsigned char)c;
+}
+
+
+
+void
+pm_readchar(FILE * const ifP,
+            char * const cP) {
+    
+    *cP = (char)getcNofail(ifP);
 }
 
 
@@ -479,18 +488,11 @@ pm_writechar(FILE * const ofP,
 int
 pm_readbigshort(FILE *  const ifP, 
                 short * const sP) {
-    int c;
 
     unsigned short s;
 
-    c = getc(ifP);
-    if (c == EOF)
-        abortWithReadError(ifP);
-    s = (c & 0xff) << 8;
-    c = getc(ifP);
-    if (c == EOF)
-        abortWithReadError(ifP);
-    s |= c & 0xff;
+    s  = getcNofail(ifP) << 8;
+    s |= getcNofail(ifP) << 0;
 
     *sP = s;
 
@@ -515,25 +517,12 @@ int
 pm_readbiglong(FILE * const ifP, 
                long * const lP) {
 
-    int c;
     unsigned long l;
 
-    c = getc(ifP);
-    if (c == EOF)
-        abortWithReadError(ifP);
-    l = c << 24;
-    c = getc(ifP);
-    if (c == EOF)
-        abortWithReadError(ifP);
-    l |= c << 16;
-    c = getc(ifP);
-    if (c == EOF)
-        abortWithReadError(ifP);
-    l |= c << 8;
-    c = getc(ifP);
-    if (c == EOF)
-        abortWithReadError(ifP);
-    l |= c;
+    l  = getcNofail(ifP) << 24;
+    l |= getcNofail(ifP) << 16;
+    l |= getcNofail(ifP) <<  8;
+    l |= getcNofail(ifP) <<  0;
 
     *lP = l;
 
@@ -559,18 +548,10 @@ pm_writebiglong(FILE * const ofP,
 int
 pm_readlittleshort(FILE *  const ifP, 
                    short * const sP) {
-    int c;
     unsigned short s;
 
-    c = getc(ifP);
-    if (c == EOF)
-        abortWithReadError(ifP);
-    s = c & 0xff;
-
-    c = getc(ifP);
-    if (c == EOF)
-        abortWithReadError(ifP);
-    s |= (c & 0xff) << 8;
+    s  = getcNofail(ifP) << 0;
+    s |= getcNofail(ifP) << 8;
 
     *sP = s;
 
@@ -594,25 +575,12 @@ pm_writelittleshort(FILE * const ofP,
 int
 pm_readlittlelong(FILE * const ifP, 
                   long * const lP) {
-    int c;
     unsigned long l;
 
-    c = getc(ifP);
-    if (c == EOF)
-        abortWithReadError(ifP);
-    l = c;
-    c = getc(ifP);
-    if (c == EOF)
-        abortWithReadError(ifP);
-    l |= c << 8;
-    c = getc(ifP);
-    if (c == EOF)
-        abortWithReadError(ifP);
-    l |= c << 16;
-    c = getc(ifP);
-    if (c == EOF)
-        abortWithReadError(ifP);
-    l |= c << 24;
+    l  = getcNofail(ifP) <<  0;
+    l |= getcNofail(ifP) <<  8;
+    l |= getcNofail(ifP) << 16;
+    l |= getcNofail(ifP) << 24;
 
     *lP = l;