summaryrefslogtreecommitdiff
path: root/cutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'cutils.c')
-rw-r--r--cutils.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/cutils.c b/cutils.c
index 80a7a1d8f0..1090aa4c77 100644
--- a/cutils.c
+++ b/cutils.c
@@ -109,6 +109,7 @@ void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint)
qiov->iov = qemu_malloc(alloc_hint * sizeof(struct iovec));
qiov->niov = 0;
qiov->nalloc = alloc_hint;
+ qiov->size = 0;
}
void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
@@ -119,6 +120,7 @@ void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
}
qiov->iov[qiov->niov].iov_base = base;
qiov->iov[qiov->niov].iov_len = len;
+ qiov->size += len;
++qiov->niov;
}
@@ -138,13 +140,18 @@ void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf)
}
}
-void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf)
+void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count)
{
const uint8_t *p = (const uint8_t *)buf;
+ size_t copy;
int i;
- for (i = 0; i < qiov->niov; ++i) {
- memcpy(qiov->iov[i].iov_base, p, qiov->iov[i].iov_len);
- p += qiov->iov[i].iov_len;
+ for (i = 0; i < qiov->niov && count; ++i) {
+ copy = count;
+ if (copy > qiov->iov[i].iov_len)
+ copy = qiov->iov[i].iov_len;
+ memcpy(qiov->iov[i].iov_base, p, copy);
+ p += copy;
+ count -= copy;
}
}