*/
static inline size_t agxblen(const agxbuf *xb) { return xb->size; }
+/// get the capacity of the backing memory of a buffer
+///
+/// In contrast to \p agxblen, this is the total number of usable bytes in the
+/// backing store, not the total number of currently stored bytes.
+///
+/// \param xb Buffer to operate on
+/// \return Number of usable bytes in the backing store
+static inline size_t agxbsizeof(const agxbuf *xb) { return xb->capacity; }
+
/* agxbpop:
* Removes last character added, if any.
*/
size_t nsize = 0; // new buffer size
char *nbuf; // new buffer
- size = xb->capacity;
+ size = agxbsizeof(xb);
nsize = size == 0 ? BUFSIZ : (2 * size);
if (size + ssz > nsize)
nsize = size + ssz;
// do we need to expand the buffer?
{
- size_t unused_space = xb->capacity - xb->size;
+ size_t unused_space = agxbsizeof(xb) - agxblen(xb);
if (unused_space < size) {
size_t extra = size - unused_space;
agxbmore(xb, extra);
if (ssz == 0) {
return 0;
}
- if (ssz > xb->capacity - xb->size)
+ if (ssz > agxbsizeof(xb) - agxblen(xb))
agxbmore(xb, ssz);
memcpy(&xb->buf[xb->size], s, ssz);
xb->size += ssz;
* int agxbputc(agxbuf*, char)
*/
static inline int agxbputc(agxbuf *xb, char c) {
- if (xb->size >= xb->capacity) {
+ if (agxblen(xb) >= agxbsizeof(xb)) {
agxbmore(xb, 1);
}
xb->buf[xb->size] = c;