Blob Blame Raw
From 4c2f805375c0dc66cdd2a30b29c03021833e02ca Mon Sep 17 00:00:00 2001
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Thu, 8 Feb 2018 17:50:19 +0100
Subject: [PATCH 05/27] buffer: add buffer_move_empty

RH-Author: Daniel P. Berrange <berrange@redhat.com>
Message-id: <20180208175041.5634-6-berrange@redhat.com>
Patchwork-id: 78934
O-Subject: [RHEL-7.5 qemu-kvm PATCH v1 05/27] buffer: add buffer_move_empty
Bugzilla: 1527405
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>

From: Gerd Hoffmann <kraxel@redhat.com>

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Lieven <pl@kamp.de>
Reviewed-by: Daniel Berrange <berrange@redhat.com>
Message-id: 1446203414-4013-4-git-send-email-kraxel@redhat.com
(cherry picked from commit 4d1eb5fdb141c9100eb82e1dc7d4547fb1decd8b)

 Conflicts:
	include/qemu/buffer.h
	util/buffer.c - APIs are still in vnc.{c,h}

Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 ui/vnc.c | 15 +++++++++++++++
 ui/vnc.h |  1 +
 2 files changed, 16 insertions(+)

diff --git a/ui/vnc.c b/ui/vnc.c
index 9047862..b520f58 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -516,6 +516,21 @@ void buffer_advance(Buffer *buf, size_t len)
     buf->offset -= len;
 }
 
+void buffer_move_empty(Buffer *to, Buffer *from)
+{
+    assert(to->offset == 0);
+
+    g_free(to->buffer);
+    to->offset = from->offset;
+    to->capacity = from->capacity;
+    to->buffer = from->buffer;
+
+    from->offset = 0;
+    from->capacity = 0;
+    from->buffer = NULL;
+}
+
+
 static void vnc_desktop_resize(VncState *vs)
 {
     if (vs->csock == -1 || !vnc_has_feature(vs, VNC_FEATURE_RESIZE)) {
diff --git a/ui/vnc.h b/ui/vnc.h
index d1badbb..c300660 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -548,6 +548,7 @@ void buffer_free(Buffer *buffer);
 void buffer_append(Buffer *buffer, const void *data, size_t len);
 void buffer_advance(Buffer *buf, size_t len);
 uint8_t *buffer_end(Buffer *buffer);
+void buffer_move_empty(Buffer *to, Buffer *from);
 
 
 /* Misc helpers */
-- 
1.8.3.1