deps/libcows/buffers.c
void *cbuf_chain_get_read_chunk(cbuf_chain *chain, size_t *chunk_size) {
    cbuf *cb;
    for(cb = STAILQ_FIRST(&chain->head); cb; cb = STAILQ_FIRST(&chain->head)) {
        size_t avail = cb->write_offset - cb->read_offset;
        if(avail) {
            *chunk_size = avail;
            return cb->read_offset;
        } else {
            if(STAILQ_NEXT(cb, next)) {
                STAILQ_REMOVE_HEAD(&chain->head, next);
                if(cb->free) cb->free(cb->buf);
                free(cb);
            } else {
                break;
            }
        }
    }
    *chunk_size = 0;
    return 0;
}
/*
 * Get the first chunk of contiguous space.
 * Returns 0 if it there is no data in chain, and sets the (*chunk_size) to 0.
 */
Get the first chunk of contiguous space.
Returns 0 if it there is no data in chain, and sets the (*chunk_size) to 0.
Get the first chunk of contiguous space . Returns 0 if it there is no data in chain and sets the ( * chunk_size ) to 0 .
void *cbuf_chain_get_read_chunk(cbuf_chain *chain, size_t *chunk_size) {
    cbuf *cb;
    for(cb = STAILQ_FIRST(&chain->head); cb; cb = STAILQ_FIRST(&chain->head)) {
        size_t avail = cb->write_offset - cb->read_offset;
        if(avail) {
            *chunk_size = avail;
            return cb->read_offset;
        } else {
            if(STAILQ_NEXT(cb, next)) {
                STAILQ_REMOVE_HEAD(&chain->head, next);
                if(cb->free) cb->free(cb->buf);
                free(cb);
            } else {
                break;
            }
        }
    }
    *chunk_size = 0;
    return 0;
}
void * cbuf_chain_get_read_chunk ( cbuf_chain * chain , size_t * chunk_size ) { cbuf * cb ; for ( cb = STAILQ_FIRST ( & chain -> head ) ; cb ; cb = STAILQ_FIRST ( & chain -> head ) ) { size_t avail = cb -> write_offset - cb -> read_offset ; if ( avail ) { * chunk_size = avail ; return cb -> read_offset ; } else { if ( STAILQ_NEXT ( cb , next ) ) { STAILQ_REMOVE_HEAD ( & chain -> head , next ) ; if ( cb -> free ) cb -> free ( cb -> buf ) ; free ( cb ) ; } else { break ; } } } * chunk_size = 0 ; return 0 ; }
Get the first chunk of contiguous space.
Get the first chunk of contiguous space .