From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55742) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwXkc-0004s4-DE for qemu-devel@nongnu.org; Wed, 11 Nov 2015 10:57:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZwXiV-0003Ax-Te for qemu-devel@nongnu.org; Wed, 11 Nov 2015 10:55:58 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:36687 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwXiV-00037z-Ao for qemu-devel@nongnu.org; Wed, 11 Nov 2015 10:53:47 -0500 From: Vladimir Sementsov-Ogievskiy Date: Wed, 11 Nov 2015 18:16:37 +0300 Message-Id: <1447255003-2043-8-git-send-email-vsementsov@virtuozzo.com> In-Reply-To: <1447255003-2043-1-git-send-email-vsementsov@virtuozzo.com> References: <1447255003-2043-1-git-send-email-vsementsov@virtuozzo.com> Subject: [Qemu-devel] [PATCH 07/13] migration/qemu-file: add qemu_put_counted_string() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, vsementsov@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, amit.shah@redhat.com, den@openvz.org, jsnow@redhat.com Add function opposite to qemu_get_counted_string. qemu_put_counted_string puts one-byte length of the string (string should not be longer than 255 characters), and then it puts the string, without last zero byte. Reviewed-by: John Snow Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/migration/qemu-file.h | 2 ++ migration/qemu-file.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index b5d08d2..ea8aef8 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -329,4 +329,6 @@ static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv) size_t qemu_get_counted_string(QEMUFile *f, char buf[256]); +void qemu_put_counted_string(QEMUFile *f, const char *name); + #endif diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 0bbd257..1e90810 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -662,6 +662,19 @@ size_t qemu_get_counted_string(QEMUFile *f, char buf[256]) } /* + * Put a string with one preceding byte containing its length. The length of + * the string should be less than 256. + */ +void qemu_put_counted_string(QEMUFile *f, const char *name) +{ + size_t len = strlen(name); + + assert(len < 256); + qemu_put_byte(f, len); + qemu_put_buffer(f, (const uint8_t *)name, len); +} + +/* * Set the blocking state of the QEMUFile. * Note: On some transports the OS only keeps a single blocking state for * both directions, and thus changing the blocking on the main -- 2.1.4