aboutsummaryrefslogtreecommitdiff
path: root/cutils.c
diff options
context:
space:
mode:
authorMichael Tokarev <mjt@tls.msk.ru>2012-03-10 16:54:23 +0400
committerMichael Tokarev <mjt@tls.msk.ru>2012-06-11 23:07:44 +0400
commit3d9b49254f893f2a3739400e536de25db1cdc5f9 (patch)
tree3d08dfabe658baba0b89a5ba675d903c3cdbbcb6 /cutils.c
parent2278a69e7020d86a8c73a28474e7709d3e7d5081 (diff)
consolidate qemu_iovec_memset{,_skip}() into single function and use existing iov_memset()
This patch combines two functions into one, and replaces the implementation with already existing iov_memset() from iov.c. The new prototype of qemu_iovec_memset(): size_t qemu_iovec_memset(qiov, size_t offset, int fillc, size_t bytes) It is different from former qemu_iovec_memset_skip(), and I want to make other functions to be consistent with it too: first how much to skip, second what, and 3rd how many of it. It also returns actual number of bytes filled in, which may be less than the requested `bytes' if qiov is smaller than offset+bytes, in the same way iov_memset() does. While at it, use utility function iov_memset() from iov.h in posix-aio-compat.c, where qiov was used. Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Diffstat (limited to 'cutils.c')
-rw-r--r--cutils.c44
1 files changed, 4 insertions, 40 deletions
diff --git a/cutils.c b/cutils.c
index af308cd7b9..0ddf4c7d74 100644
--- a/cutils.c
+++ b/cutils.c
@@ -26,6 +26,7 @@
#include <math.h>
#include "qemu_socket.h"
+#include "iov.h"
void pstrcpy(char *buf, int buf_size, const char *str)
{
@@ -260,47 +261,10 @@ void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count)
}
}
-void qemu_iovec_memset(QEMUIOVector *qiov, int c, size_t count)
+size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset,
+ int fillc, size_t bytes)
{
- size_t n;
- int i;
-
- for (i = 0; i < qiov->niov && count; ++i) {
- n = MIN(count, qiov->iov[i].iov_len);
- memset(qiov->iov[i].iov_base, c, n);
- count -= n;
- }
-}
-
-void qemu_iovec_memset_skip(QEMUIOVector *qiov, int c, size_t count,
- size_t skip)
-{
- int i;
- size_t done;
- void *iov_base;
- uint64_t iov_len;
-
- done = 0;
- for (i = 0; (i < qiov->niov) && (done != count); i++) {
- if (skip >= qiov->iov[i].iov_len) {
- /* Skip the whole iov */
- skip -= qiov->iov[i].iov_len;
- continue;
- } else {
- /* Skip only part (or nothing) of the iov */
- iov_base = (uint8_t*) qiov->iov[i].iov_base + skip;
- iov_len = qiov->iov[i].iov_len - skip;
- skip = 0;
- }
-
- if (done + iov_len > count) {
- memset(iov_base, c, count - done);
- break;
- } else {
- memset(iov_base, c, iov_len);
- }
- done += iov_len;
- }
+ return iov_memset(qiov->iov, qiov->niov, offset, fillc, bytes);
}
/*