Am 24.09.2015 um 10:42 schrieb Gerd Hoffmann: > Signed-off-by: Gerd Hoffmann <kra...@redhat.com> > --- > include/io/buffer.h | 10 ++++++++++ > io/buffer.c | 16 ++++++++++++++++ > 2 files changed, 26 insertions(+) > > diff --git a/include/io/buffer.h b/include/io/buffer.h > index 1dddc73..5676aff 100644 > --- a/include/io/buffer.h > +++ b/include/io/buffer.h > @@ -137,4 +137,14 @@ gboolean qio_buffer_empty(QIOBuffer *buffer); > */ > void qio_buffer_move_empty(QIOBuffer *to, QIOBuffer *from); > > +/** > + * qio_buffer_move: > + * @to: destination buffer object > + * @from: source buffer object > + * > + * Moves buffer, copying data (unless 'to' buffer happens to be empty). > + * 'from' buffer is empty and zero-sized on return. > + */ > +void qio_buffer_move(QIOBuffer *to, QIOBuffer *from); > + > #endif /* QIO_BUFFER_H__ */ > diff --git a/io/buffer.c b/io/buffer.c > index 09ca321..96077d3 100644 > --- a/io/buffer.c > +++ b/io/buffer.c > @@ -91,3 +91,19 @@ void qio_buffer_move_empty(QIOBuffer *to, QIOBuffer *from) > from->capacity = 0; > from->buffer = NULL; > } > + > +void qio_buffer_move(QIOBuffer *to, QIOBuffer *from) > +{ > + if (to->offset == 0) { > + qio_buffer_move_empty(to, from); > + return; > + } > + > + qio_buffer_reserve(to, from->offset); > + qio_buffer_append(to, from->buffer, from->offset); > + > + g_free(from->buffer); > + from->offset = 0; > + from->capacity = 0; > + from->buffer = NULL; > +}
Reviewed-by: Peter Lieven <p...@kamp.de>