diff options
author | Anand Avati <avati@redhat.com> | 2012-07-12 22:48:13 -0700 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2012-07-16 02:23:26 -0700 |
commit | 911603eb0e1c85e79cf261f99f442c833ead8178 (patch) | |
tree | de9a483ebc389cc237ece2033ffe1050766361a9 | |
parent | 01fe42db6e185ee7eb59677af9bc5bdf174bf548 (diff) |
common-utils: implement iov_copy
Change-Id: I7ab97279dafc1211b417e1c03332572887453c66
BUG: 839950
Signed-off-by: Anand Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.com/3663
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Shishir Gowda <sgowda@redhat.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
-rw-r--r-- | libglusterfs/src/common-utils.h | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 86e4e53cc96..26af45fcc7b 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -267,7 +267,7 @@ iov_length (const struct iovec *vector, int count) static inline struct iovec * -iov_dup (struct iovec *vector, int count) +iov_dup (const struct iovec *vector, int count) { int bytecount = 0; int i; @@ -347,6 +347,43 @@ iov_unload (char *buf, const struct iovec *vector, int count) } +static inline size_t +iov_copy (const struct iovec *dst, int dcnt, + const struct iovec *src, int scnt) +{ + size_t ret = 0; + size_t left = 0; + size_t min_i = 0; + int s_i = 0, s_ii = 0; + int d_i = 0, d_ii = 0; + + ret = min (iov_length (dst, dcnt), iov_length (src, scnt)); + left = ret; + + while (left) { + min_i = min (dst[d_i].iov_len - d_ii, src[s_i].iov_len - s_ii); + memcpy (dst[d_i].iov_base + d_ii, src[s_i].iov_base + s_ii, + min_i); + + d_ii += min_i; + if (d_ii == dst[d_i].iov_len) { + d_ii = 0; + d_i++; + } + + s_ii += min_i; + if (s_ii == src[s_i].iov_len) { + s_ii = 0; + s_i++; + } + + left -= min_i; + } + + return ret; +} + + static inline int mem_0filled (const char *buf, size_t size) { |