/* Structure defining a buffer's head */
struct buffer {
size_t head; /* start offset of remaining data relative to area */
- size_t len; /* length of data after head */
+ size_t data; /* amount of data after head including wrapping */
size_t size; /* buffer size in bytes */
char area[0]; /* <size> bytes of stored data */
};
/* b_data() : returns the number of bytes present in the buffer. */
static inline size_t b_data(const struct buffer *b)
{
- return b->len;
+ return b->data;
}
/* b_room() : returns the amount of room left in the buffer */
*/
static inline size_t __b_stop_ofs(const struct buffer *b)
{
- return b->head + b->len;
+ return b->head + b->data;
}
static inline const char *__b_stop(const struct buffer *b)
static inline void b_reset(struct buffer *b)
{
b->head = 0;
- b->len = 0;
+ b->data = 0;
}
/* b_sub() : decreases the buffer length by <count> */
static inline void b_sub(struct buffer *b, size_t count)
{
- b->len -= count;
+ b->data -= count;
}
/* b_add() : increase the buffer length by <count> */
static inline void b_add(struct buffer *b, size_t count)
{
- b->len += count;
+ b->data += count;
}
/* b_set_data() : sets the buffer's length */
static inline void b_set_data(struct buffer *b, size_t len)
{
- b->len = len;
+ b->data = len;
}
/* b_del() : skips <del> bytes in a buffer <b>. Covers both the output and the
*/
static inline void b_del(struct buffer *b, size_t del)
{
- b->len -= del;
+ b->data -= del;
b->head += del;
if (b->head >= b->size)
b->head -= b->size;
if (b_full(b))
return;
*b_tail(b) = c;
- b->len++;
+ b->data++;
}
/* b_putblk() : tries to append block <blk> at the end of buffer <b>. Supports
half = len;
memcpy(b_tail(b), blk, half);
- b->len += half;
+ b->data += half;
if (len > half) {
memcpy(b_tail(b), blk + half, len - half);
- b->len += len - half;
+ b->data += len - half;
}
return len;
}
/* Sets the amount of output for the channel */
static inline void co_set_data(struct channel *c, size_t output)
{
- c->buf->len += output - c->output;
+ c->buf->data += output - c->output;
c->output = output;
}
if (!ci_data(chn))
return;
- chn->buf->len = co_data(chn);
+ chn->buf->data = co_data(chn);
}
/* This function realigns a possibly wrapping channel buffer so that the input