added buffer_fwd_offset() so I don't have to alloc mem to ignore some chunk of a buffer

This commit is contained in:
git@daemon.de
2014-08-06 20:19:28 +02:00
parent 7542128486
commit a3f1bdaa2e
2 changed files with 24 additions and 0 deletions

View File

@@ -145,6 +145,19 @@ size_t buffer_get_chunk(Buffer *b, void *buf, size_t len) {
return len;
}
size_t buffer_fwd_offset(Buffer *b, size_t fwdby) {
if(fwdby > b->end - b->offset) {
final("[buffer %s] attempt to set offset %ld bytes forward data from buffer with %ld bytes left at offset %ld\n",
b->name, fwdby, b->end - b->offset, b->offset);
}
else if(fwdby == 0) {
return 0;
}
b->offset += fwdby;
return fwdby;
}
size_t buffer_get_chunk_tobuf(Buffer *b, Buffer *dst, size_t len) {
if(len > b->end - b->offset) {
final("[buffer %s] attempt to read %ld bytes data from buffer with %ld bytes left at offset %ld\n",