aboutsummaryrefslogtreecommitdiff
path: root/iov.c
diff options
context:
space:
mode:
authorHannes Reinecke <hare@suse.de>2011-07-11 15:02:23 +0200
committerKevin Wolf <kwolf@redhat.com>2011-07-18 16:06:27 +0200
commit348e7b8dcd1460df4d681105f63dd90bba70496d (patch)
tree5df2392581adad67c863127448a0e73e8c2ed0b3 /iov.c
parent5afc8b3de9a8a472a45d2b980632a15cb7f1e1c3 (diff)
iov: Update parameter usage in iov_(to|from)_buf()
iov_to_buf() has an 'offset' parameter, iov_from_buf() hasn't. This patch adds the missing parameter to iov_from_buf(). It also renames the 'offset' parameter to 'iov_off' to emphasize it's the offset into the iovec and not the buffer. Signed-off-by: Hannes Reinecke <hare@suse.de> Acked-by: Alexander Graf <agraf@suse.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'iov.c')
-rw-r--r--iov.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/iov.c b/iov.c
index 588cd04288..1e027914d4 100644
--- a/iov.c
+++ b/iov.c
@@ -14,56 +14,61 @@
#include "iov.h"
-size_t iov_from_buf(struct iovec *iov, unsigned int iovcnt,
- const void *buf, size_t size)
+size_t iov_from_buf(struct iovec *iov, unsigned int iov_cnt,
+ const void *buf, size_t iov_off, size_t size)
{
- size_t offset;
+ size_t iovec_off, buf_off;
unsigned int i;
- offset = 0;
- for (i = 0; offset < size && i < iovcnt; i++) {
- size_t len;
+ iovec_off = 0;
+ buf_off = 0;
+ for (i = 0; i < iov_cnt && size; i++) {
+ if (iov_off < (iovec_off + iov[i].iov_len)) {
+ size_t len = MIN((iovec_off + iov[i].iov_len) - iov_off, size);
- len = MIN(iov[i].iov_len, size - offset);
+ memcpy(iov[i].iov_base + (iov_off - iovec_off), buf + buf_off, len);
- memcpy(iov[i].iov_base, buf + offset, len);
- offset += len;
+ buf_off += len;
+ iov_off += len;
+ size -= len;
+ }
+ iovec_off += iov[i].iov_len;
}
- return offset;
+ return buf_off;
}
-size_t iov_to_buf(const struct iovec *iov, const unsigned int iovcnt,
- void *buf, size_t offset, size_t size)
+size_t iov_to_buf(const struct iovec *iov, const unsigned int iov_cnt,
+ void *buf, size_t iov_off, size_t size)
{
uint8_t *ptr;
- size_t iov_off, buf_off;
+ size_t iovec_off, buf_off;
unsigned int i;
ptr = buf;
- iov_off = 0;
+ iovec_off = 0;
buf_off = 0;
- for (i = 0; i < iovcnt && size; i++) {
- if (offset < (iov_off + iov[i].iov_len)) {
- size_t len = MIN((iov_off + iov[i].iov_len) - offset , size);
+ for (i = 0; i < iov_cnt && size; i++) {
+ if (iov_off < (iovec_off + iov[i].iov_len)) {
+ size_t len = MIN((iovec_off + iov[i].iov_len) - iov_off , size);
- memcpy(ptr + buf_off, iov[i].iov_base + (offset - iov_off), len);
+ memcpy(ptr + buf_off, iov[i].iov_base + (iov_off - iovec_off), len);
buf_off += len;
- offset += len;
+ iov_off += len;
size -= len;
}
- iov_off += iov[i].iov_len;
+ iovec_off += iov[i].iov_len;
}
return buf_off;
}
-size_t iov_size(const struct iovec *iov, const unsigned int iovcnt)
+size_t iov_size(const struct iovec *iov, const unsigned int iov_cnt)
{
size_t len;
unsigned int i;
len = 0;
- for (i = 0; i < iovcnt; i++) {
+ for (i = 0; i < iov_cnt; i++) {
len += iov[i].iov_len;
}
return len;