// give some data, advancing position but not forgetting yet. static mpg_ssize_t bc_give( bufferchain_t *bc, byte *out, mpg_ssize_t size ) { buffy_t *b = bc->first; mpg_ssize_t gotcount = 0; mpg_ssize_t offset = 0; if( bc->size - bc->pos < size ) return bc_need_more( bc ); // find the current buffer while( b != NULL && ( offset + b->size ) <= bc->pos ) { offset += b->size; b = b->next; } // now start copying from there while( gotcount < size && ( b != NULL )) { mpg_ssize_t loff = bc->pos - offset; mpg_ssize_t chunk = size - gotcount; // amount of bytes to get from here... if( chunk > b->size - loff ) chunk = b->size - loff; memcpy( out + gotcount, b->data + loff, chunk ); gotcount += chunk; bc->pos += chunk; offset += b->size; b = b->next; } return gotcount; }
/* Skip some bytes and return the new position. The buffers are still there, just the read pointer is moved! */ static ssize_t bc_skip(struct bufferchain *bc, ssize_t count) { if(count >= 0) { if(bc->size - bc->pos < count) return bc_need_more(bc); else return bc->pos += count; } else return READER_ERROR; }
// skip some bytes and return the new position. // the buffers are still there, just the read pointer is moved! static mpg_ssize_t bc_skip( bufferchain_t *bc, mpg_ssize_t count ) { if( count >= 0 ) { if( bc->size - bc->pos < count ) return bc_need_more( bc ); return bc->pos += count; } return MPG123_ERR; }
/* Give some data, advancing position but not forgetting yet. */ static ssize_t bc_give(struct bufferchain *bc, unsigned char *out, ssize_t size) { struct buffy *b = bc->first; ssize_t gotcount = 0; ssize_t offset = 0; if(bc->size - bc->pos < size) return bc_need_more(bc); /* find the current buffer */ while(b != NULL && (offset + b->size) <= bc->pos) { offset += b->size; b = b->next; } /* now start copying from there */ while(gotcount < size && (b != NULL)) { ssize_t loff = bc->pos - offset; ssize_t chunk = size - gotcount; /* amount of bytes to get from here... */ if(chunk > b->size - loff) chunk = b->size - loff; #ifdef EXTRA_DEBUG debug3("copying %liB from %p+%li",(long)chunk, b->data, (long)loff); */ #endif memcpy(out+gotcount, b->data+loff, chunk); gotcount += chunk; bc->pos += chunk; offset += b->size; b = b->next; } #ifdef EXTRA_DEBUG debug2("got %li bytes, pos advanced to %li", (long)gotcount, (long)bc->pos); #endif return gotcount; }