summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'cutils.c')
-rw-r--r--cutils.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/cutils.c b/cutils.c
index 9f26dd9fc..5b36cc6b6 100644
--- a/cutils.c
+++ b/cutils.c
@@ -23,6 +23,7 @@
*/
#include "qemu-common.h"
#include "host-utils.h"
+#include <assert.h>
void pstrcpy(char *buf, int buf_size, const char *str)
{
@@ -151,8 +152,22 @@ void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint)
qiov->size = 0;
}
+void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov)
+{
+ int i;
+
+ qiov->iov = iov;
+ qiov->niov = niov;
+ qiov->nalloc = -1;
+ qiov->size = 0;
+ for (i = 0; i < niov; i++)
+ qiov->size += iov[i].iov_len;
+}
+
void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
{
+ assert(qiov->nalloc != -1);
+
if (qiov->niov == qiov->nalloc) {
qiov->nalloc = 2 * qiov->nalloc + 1;
qiov->iov = qemu_realloc(qiov->iov, qiov->nalloc * sizeof(struct iovec));
@@ -165,11 +180,15 @@ void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
void qemu_iovec_destroy(QEMUIOVector *qiov)
{
+ assert(qiov->nalloc != -1);
+
qemu_free(qiov->iov);
}
void qemu_iovec_reset(QEMUIOVector *qiov)
{
+ assert(qiov->nalloc != -1);
+
qiov->niov = 0;
qiov->size = 0;
}