src/buffer.c

changeset 1131
644f77f903b1
parent 1128
3672b89e606c
equal deleted inserted replaced
1130:5bcb725119b6 1131:644f77f903b1
354 size_t size, 354 size_t size,
355 size_t nitems, 355 size_t nitems,
356 CxBuffer *buffer 356 CxBuffer *buffer
357 ) { 357 ) {
358 size_t pos = buffer->pos; 358 size_t pos = buffer->pos;
359 buffer->pos = buffer->size; 359 size_t append_pos = buffer->size;
360 buffer->pos = append_pos;
360 size_t written = cxBufferWrite(ptr, size, nitems, buffer); 361 size_t written = cxBufferWrite(ptr, size, nitems, buffer);
361 buffer->pos = pos; 362 // the buffer might have been flushed
363 // we must compute a possible delta for the position
364 // expected: pos = append_pos + written
365 // -> if this is not the case, there is a delta
366 size_t delta = append_pos + written*size - buffer->pos;
367 if (delta > pos) {
368 buffer->pos = 0;
369 } else {
370 buffer->pos = pos - delta;
371 }
362 return written; 372 return written;
363 } 373 }
364 374
365 int cxBufferPut( 375 int cxBufferPut(
366 CxBuffer *buffer, 376 CxBuffer *buffer,

mercurial