On 08/05/11 13:30, Kevin Wolf wrote:
Am 04.08.2011 17:10, schrieb Gerd Hoffmann:
Fill the spefified area with zeros.

Signed-off-by: Gerd Hoffmann<kra...@redhat.com>

Looks like we're starting to duplicate everything in qemu_iovec_* and
iov_*...

Any reason not to use QEMUIOVector?

I *do* use QEMUIOVector, but for the actual copy I'm using iov_{from,to}_buf() instead of qemu_iovec_{from,to}_buffer because the former allows to specify an offset.

But, yea, we have some duplication here, qemu_iovec_* can just call iov_* instead of reimplementing stuff ...

cheers,
  Gerd

diff --git a/cutils.c b/cutils.c
index f9a7e36..b8ca4c2 100644
--- a/cutils.c
+++ b/cutils.c
@@ -24,6 +24,7 @@
 #include "qemu-common.h"
 #include "host-utils.h"
 #include <math.h>
+#include "iov.h"
 
 void pstrcpy(char *buf, int buf_size, const char *str)
 {
@@ -230,29 +231,12 @@ void qemu_iovec_reset(QEMUIOVector *qiov)
 
 void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf)
 {
-    uint8_t *p = (uint8_t *)buf;
-    int i;
-
-    for (i = 0; i < qiov->niov; ++i) {
-        memcpy(p, qiov->iov[i].iov_base, qiov->iov[i].iov_len);
-        p += qiov->iov[i].iov_len;
-    }
+    iov_to_buf(qiov->iov, qiov->niov, buf, 0, qiov->size);
 }
 
 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 && 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;
-    }
+    iov_from_buf(qiov->iov, qiov->niov, buf, 0, count);
 }
 
 void qemu_iovec_memset(QEMUIOVector *qiov, int c, size_t count)

Reply via email to