}
size_t nAvail;
- nAvail = (end - ptr) / itemSize;
+ nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
flush();
// Still not enough space?
- if (itemSize > (size_t)(end - ptr)) {
+ if (itemSize > avail()) {
// Can we shuffle things around?
// (don't do this if it gains us less than 25%)
if (((size_t)(sentUpTo - start) > bufSize / 4) &&
}
size_t nAvail;
- nAvail = (end - ptr) / itemSize;
+ nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
}
size_t nAvail;
- nAvail = (end - ptr) / itemSize;
+ nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
offset += ptr - start;
ptr = start;
- while ((size_t)(end - ptr) < itemSize) {
+ while (avail() < itemSize) {
size_t n = in_stream.check(2, 1, wait);
if (n == 0) return 0;
const U8* iptr = in_stream.getptr();
}
size_t nAvail;
- nAvail = (end - ptr) / itemSize;
+ nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
writeBuffer();
size_t nAvail;
- nAvail = (end - ptr) / itemSize;
+ nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
virtual ~InStream() {}
+ // avail() returns the number of bytes that are currenctly directly
+ // available from the stream.
+
+ inline size_t avail()
+ {
+ return end - ptr;
+ }
+
// check() ensures there is buffer data for at least one item of size
// itemSize bytes. Returns the number of items in the buffer (up to a
// maximum of nItems). If wait is false, then instead of blocking to wait
{
size_t nAvail;
- if (itemSize > (size_t)(end - ptr))
+ if (itemSize > avail())
return overrun(itemSize, nItems, wait);
- nAvail = (end - ptr) / itemSize;
+ nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
virtual ~OutStream() {}
+ // avail() returns the number of bytes that currently be written to the
+ // stream without any risk of blocking.
+
+ inline size_t avail()
+ {
+ return end - ptr;
+ }
+
// check() ensures there is buffer space for at least one item of size
// itemSize bytes. Returns the number of items which fit (up to a maximum
// of nItems).
{
size_t nAvail;
- if (itemSize > (size_t)(end - ptr))
+ if (itemSize > avail())
return overrun(itemSize, nItems);
- nAvail = (end - ptr) / itemSize;
+ nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
}
size_t nAvail;
- nAvail = (end - ptr) / itemSize;
+ nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
}
size_t nAvail;
- nAvail = (end - ptr) / itemSize;
+ nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
flush();
size_t nAvail;
- nAvail = (end - ptr) / itemSize;
+ nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
end -= ptr - start;
ptr = start;
- while ((size_t)(end - ptr) < itemSize) {
+ while (avail() < itemSize) {
if (!decompress(wait))
return 0;
}
size_t nAvail;
- nAvail = (end - ptr) / itemSize;
+ nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
size_t n = underlying->check(1, 1, wait);
if (n == 0) return false;
zs->next_in = (U8*)underlying->getptr();
- zs->avail_in = underlying->getend() - underlying->getptr();
+ zs->avail_in = underlying->avail();
if (zs->avail_in > bytesIn)
zs->avail_in = bytesIn;
checkCompressionLevel();
- while ((size_t)(end - ptr) < itemSize) {
+ while (avail() < itemSize) {
zs->next_in = start;
zs->avail_in = ptr - start;
}
size_t nAvail;
- nAvail = (end - ptr) / itemSize;
+ nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
do {
underlying->check(1);
zs->next_out = underlying->getptr();
- zs->avail_out = underlying->getend() - underlying->getptr();
+ zs->avail_out = underlying->avail();
#ifdef ZLIBOUT_DEBUG
vlog.debug("calling deflate, avail_in %d, avail_out %d",
jc->clear();
dest->pub.next_output_byte = jc->getptr();
- dest->pub.free_in_buffer = jc->getend() - jc->getptr();
+ dest->pub.free_in_buffer = jc->avail();
}
static boolean
jc->setptr(jc->getend());
jc->overrun(jc->getend() - jc->getstart(), 1);
dest->pub.next_output_byte = jc->getptr();
- dest->pub.free_in_buffer = jc->getend() - jc->getptr();
+ dest->pub.free_in_buffer = jc->avail();
return TRUE;
}
size_t DummyOutStream::overrun(size_t itemSize, size_t nItems)
{
flush();
- if (itemSize * nItems > (size_t)(end - ptr))
- nItems = (end - ptr) / itemSize;
+ if (itemSize * nItems > avail())
+ nItems = avail() / itemSize;
return nItems;
}
size_t DummyOutStream::overrun(size_t itemSize, size_t nItems)
{
flush();
- if (itemSize * nItems > (size_t)(end - ptr))
- nItems = (end - ptr) / itemSize;
+ if (itemSize * nItems > avail())
+ nItems = avail() / itemSize;
return nItems;
}