sf_iov.[hc] add function sf_iova_memcpy_ex
parent
52e34ca393
commit
2d177ab262
|
|
@ -55,6 +55,7 @@ int sf_iova_consume(SFDynamicIOVArray *iova, const int consume_len)
|
||||||
if (iova->cnt == 0) {
|
if (iova->cnt == 0) {
|
||||||
struct iovec *last;
|
struct iovec *last;
|
||||||
|
|
||||||
|
/* update the last iov for next slice */
|
||||||
last = iob - 1;
|
last = iob - 1;
|
||||||
last->iov_base = (char *)last->iov_base + last->iov_len;
|
last->iov_base = (char *)last->iov_base + last->iov_len;
|
||||||
last->iov_len = 0;
|
last->iov_len = 0;
|
||||||
|
|
|
||||||
27
src/sf_iov.h
27
src/sf_iov.h
|
|
@ -82,6 +82,33 @@ int sf_iova_memset_ex(const struct iovec *iov, const int iovcnt,
|
||||||
#define sf_iova_memset(iova, c, offset, length) \
|
#define sf_iova_memset(iova, c, offset, length) \
|
||||||
sf_iova_memset_ex((iova).iov, (iova).cnt, 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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue