/*
* Read some data, adding it to the expanding buffer.
*
* This will ensure that the buffer has enough space to hold the new data
* (plus the previous contents).
*/
static int ebReadData(ExpandBuf* pBuf, FILE* in, size_t count, int eofExpected)
{
size_t actual;
assert(count > 0);
ebEnsureCapacity(pBuf, count);
actual = fread(pBuf->storage + pBuf->curLen, 1, count, in);
if (actual != count) {
if (eofExpected && feof(in) && !ferror(in)) {
/* return without reporting an error */
} else {
fprintf(stderr, "ERROR: read %d of %d bytes\n", actual, count);
return -1;
}
}
pBuf->curLen += count;
assert(pBuf->curLen <= pBuf->maxLen);
return 0;
}