334
334
*b++ = (char) (ch); \
337
/* Extend the buffer by twice its current size via reallociation and
337
/* Extend the buffer by twice its current size via reallocation and
338
338
reset the pointers that pointed into the old allocation to point to
339
339
the correct places in the new allocation. If extending the buffer
340
results in it being larger than 1 << 16, then flag memory exhausted. */
340
results in it being larger than EXTEND_BUFFER_MAX, then flag memory
343
/* Microsoft C 16-bit versions limit malloc to approx 65512 bytes.
344
The REALLOC define eliminates a flurry of conversion warnings,
345
but is not required. */
346
#define EXTEND_BUFFER_MAX 65500L
347
#define REALLOC(p,s) realloc(p, (size_t) (s))
349
#define EXTEND_BUFFER_MAX (1L << 16)
350
#define REALLOC realloc
341
352
#define EXTEND_BUFFER \
342
353
{ char *old_buffer = bufp->buffer; \
343
if (bufp->allocated == (1L<<16)) goto too_big; \
354
if (bufp->allocated == EXTEND_BUFFER_MAX) goto too_big; \
344
355
bufp->allocated *= 2; \
345
if (bufp->allocated > (1L<<16)) bufp->allocated = (1L<<16); \
346
bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated); \
356
if (bufp->allocated > EXTEND_BUFFER_MAX) \
357
bufp->allocated = EXTEND_BUFFER_MAX; \
358
bufp->buffer = (char *) REALLOC (bufp->buffer, bufp->allocated); \
347
359
if (bufp->buffer == 0) \
348
360
goto memory_exhausted; \
349
361
b = (b - old_buffer) + bufp->buffer; \