sf_iov.[hc] add function sf_iova_memcpy_ex

posix_api
YuQing 2022-02-14 10:26:25 +08:00
parent 52e34ca393
commit 2d177ab262
2 changed files with 28 additions and 0 deletions

View File

@ -55,6 +55,7 @@ int sf_iova_consume(SFDynamicIOVArray *iova, const int consume_len)
if (iova->cnt == 0) {
struct iovec *last;
/* update the last iov for next slice */
last = iob - 1;
last->iov_base = (char *)last->iov_base + last->iov_len;
last->iov_len = 0;

View File

@ -82,6 +82,33 @@ int sf_iova_memset_ex(const struct iovec *iov, const int iovcnt,
#define sf_iova_memset(iova, c, offset, length) \
sf_iova_memset_ex((iova).iov, (iova).cnt, c, offset, length)
static inline void sf_iova_memcpy_ex(const struct iovec *iov,
const int iovcnt, const char *buff, const int length)
{
const struct iovec *iob;
const struct iovec *end;
const char *current;
int remain;
int bytes;
current = buff;
remain = length;
end = iov + iovcnt;
for (iob=iov; iob<end; iob++) {
bytes = FC_MIN(remain, iob->iov_len);
memcpy(iob->iov_base, current, bytes);
remain -= bytes;
if (remain == 0) {
break;
}
current += bytes;
}
}
#define sf_iova_memcpy(iova, buff, length) \
sf_iova_memcpy_ex((iova).iov, (iova).cnt, buff, length)
#ifdef __cplusplus
}
#endif