deps/libcows/buffers.c
void *cbuf_chain_get_write_chunk(cbuf_chain *chain, size_t *size, int guarantee) {
    cbuf *cb = STAILQ_LAST(&chain->head, cbuf, next);
    if(cb) {
        size_t space = cb->buffer_end - cb->write_offset;
        if(space >= guarantee) {
            *size = space;
            return cb->write_offset;
        } else if(cb->write_offset == cb->read_offset) {
            cb->write_offset = cb->read_offset = cb->buf;
            *size = cb->buffer_end - cb->write_offset;
            assert(*size >= guarantee);
            return cb->write_offset;
        }
    }
    cb = cbuf_new(chain->chunk_size);
    STAILQ_INSERT_TAIL(&chain->head, cb, next);
    *size = cb->buffer_end - cb->write_offset;
    assert(*size >= guarantee);
    return cb->write_offset;
}
/*
 * Return a contiguous space into which to write. 
 */
Return a contiguous space into which to write.
Return a contiguous space into which to write .
void *cbuf_chain_get_write_chunk(cbuf_chain *chain, size_t *size, int guarantee) {
    cbuf *cb = STAILQ_LAST(&chain->head, cbuf, next);
    if(cb) {
        size_t space = cb->buffer_end - cb->write_offset;
        if(space >= guarantee) {
            *size = space;
            return cb->write_offset;
        } else if(cb->write_offset == cb->read_offset) {
            cb->write_offset = cb->read_offset = cb->buf;
            *size = cb->buffer_end - cb->write_offset;
            assert(*size >= guarantee);
            return cb->write_offset;
        }
    }
    cb = cbuf_new(chain->chunk_size);
    STAILQ_INSERT_TAIL(&chain->head, cb, next);
    *size = cb->buffer_end - cb->write_offset;
    assert(*size >= guarantee);
    return cb->write_offset;
}
void * cbuf_chain_get_write_chunk ( cbuf_chain * chain , size_t * size , int guarantee ) { cbuf * cb = STAILQ_LAST ( & chain -> head , cbuf , next ) ; if ( cb ) { size_t space = cb -> buffer_end - cb -> write_offset ; if ( space >= guarantee ) { * size = space ; return cb -> write_offset ; } else if ( cb -> write_offset == cb -> read_offset ) { cb -> write_offset = cb -> read_offset = cb -> buf ; * size = cb -> buffer_end - cb -> write_offset ; assert ( * size >= guarantee ) ; return cb -> write_offset ; } } cb = cbuf_new ( chain -> chunk_size ) ; STAILQ_INSERT_TAIL ( & chain -> head , cb , next ) ; * size = cb -> buffer_end - cb -> write_offset ; assert ( * size >= guarantee ) ; return cb -> write_offset ; }
Return a contiguous space into which to write.
Return a contiguous space into which to write .