aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2020-12-27 03:37:26 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2020-12-27 03:37:26 +0000
commit90846c9fe88372bdfd3a81220b4b80394b30cd43 (patch)
tree7d5ed3b27354ed650e302dc3fe4f7123c383b187
parent02cd57520ca330a51954682a9540b191e9d7b849 (diff)
downloadnetpbm-mirror-90846c9fe88372bdfd3a81220b4b80394b30cd43.tar.gz
netpbm-mirror-90846c9fe88372bdfd3a81220b4b80394b30cd43.tar.xz
netpbm-mirror-90846c9fe88372bdfd3a81220b4b80394b30cd43.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4011 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--lib/pmfileio.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/lib/pmfileio.c b/lib/pmfileio.c
index bea01abe..4048e74d 100644
--- a/lib/pmfileio.c
+++ b/lib/pmfileio.c
@@ -31,6 +31,7 @@
/* This makes the the x64() functions available on AIX */
#include "netpbm/pm_config.h"
+#include <stdbool.h>
#include <unistd.h>
#include <assert.h>
#include <stdio.h>
@@ -799,48 +800,50 @@ pm_readmagicnumber(FILE * const ifP) {
Oliver Trepte, oliver@fysik4.kth.se, 930613
*/
-#define PM_BUF_SIZE 16384 /* First try this size of the buffer, then
- double this until we reach PM_MAX_BUF_INC */
-#define PM_MAX_BUF_INC 65536 /* Don't allocate more memory in larger blocks
- than this. */
+static size_t const initBufSz = 16384;
+ /* First try this size of the buffer, then
+ double this until we reach 'maxBufInc' */
+static size_t const maxBufInc = 65536;
+ /* Don't allocate more memory in larger blocks than this. */
char *
-pm_read_unknown_size(FILE * const file,
- long * const nread) {
- long nalloc;
+pm_read_unknown_size(FILE * const ifP,
+ long * const nReadP) {
+ size_t nAlloc;
char * buf;
+ size_t nRead;
bool eof;
- *nread = 0;
- nalloc = PM_BUF_SIZE;
- MALLOCARRAY(buf, nalloc);
+ nAlloc = initBufSz; /* initial value */
- if (!buf)
- pm_error("Failed to allocate %lu bytes for read buffer",
- (unsigned long) nalloc);
+ MALLOCARRAY(buf, nAlloc);
- eof = FALSE; /* initial value */
+ if (!buf)
+ pm_error("Failed to allocate %lu bytes for read buffer", nAlloc);
- while(!eof) {
+ for (eof = false, nRead = 0; !eof; ) {
int val;
- if (*nread >= nalloc) { /* We need a larger buffer */
- if (nalloc > PM_MAX_BUF_INC)
- nalloc += PM_MAX_BUF_INC;
+ if (nRead >= nAlloc) { /* We need a larger buffer */
+ if (nAlloc > maxBufInc)
+ nAlloc += maxBufInc;
else
- nalloc += nalloc;
- REALLOCARRAY(buf, nalloc);
+ nAlloc += nAlloc;
+ REALLOCARRAY(buf, nAlloc);
if (!buf)
pm_error("Failed to allocate %lu bytes for read buffer",
- (unsigned long) nalloc);
+ nAlloc);
}
- val = getc(file);
+ val = getc(ifP);
if (val == EOF)
- eof = TRUE;
+ eof = true;
else
- buf[(*nread)++] = val;
+ buf[nRead++] = val;
}
+
+ *nReadP = (long)nRead;
+
return buf;
}