aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2015-10-30 12:09:59 +0100
committerGerd Hoffmann <kraxel@redhat.com>2015-11-05 09:08:39 +0100
commit830a9583206a051c240b74c3f688a015dc5d2967 (patch)
tree83bdc81fb50daf35dbfed83761fa232a1108eddf /util
parent4d1eb5fdb141c9100eb82e1dc7d4547fb1decd8b (diff)
buffer: add buffer_move
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Peter Lieven <pl@kamp.de> Reviewed-by: Daniel P. Berrange <berrange@redhat.com> Message-id: 1446203414-4013-5-git-send-email-kraxel@redhat.com
Diffstat (limited to 'util')
-rw-r--r--util/buffer.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/util/buffer.c b/util/buffer.c
index c7a39ec5da..e8f798e620 100644
--- a/util/buffer.c
+++ b/util/buffer.c
@@ -91,3 +91,19 @@ void buffer_move_empty(Buffer *to, Buffer *from)
from->capacity = 0;
from->buffer = NULL;
}
+
+void buffer_move(Buffer *to, Buffer *from)
+{
+ if (to->offset == 0) {
+ buffer_move_empty(to, from);
+ return;
+ }
+
+ buffer_reserve(to, from->offset);
+ buffer_append(to, from->buffer, from->offset);
+
+ g_free(from->buffer);
+ from->offset = 0;
+ from->capacity = 0;
+ from->buffer = NULL;
+}