1
0
mirror of https://passt.top/passt synced 2024-12-22 05:35:23 +00:00

iov: Improve documentation of iov_skip_bytes()

As pointed out in review, the documentation comments for iov_skip_bytes()
are more confusing than they should be.  Reword them, including updating
parameter names, to make it clearer.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2024-03-01 15:06:44 +11:00 committed by Stefano Brivio
parent bb11d15495
commit 137ce01789
2 changed files with 15 additions and 15 deletions

28
iov.c
View File

@ -26,31 +26,31 @@
#include "iov.h" #include "iov.h"
/* iov_skip_bytes() - Skip the first n bytes into an IO vector /* iov_skip_bytes() - Skip leading bytes of an IO vector
* @iov: IO vector * @iov: IO vector
* @n: Number of entries in @iov * @n: Number of entries in @iov
* @vec_offset: Total byte offset into the IO vector * @skip: Number of leading bytes of @iov to skip
* @buf_offset: Offset into a single buffer of the IO vector * @offset: Offset of first unskipped byte in its @iov entry
* *
* Return: index I of individual struct iovec which contains the byte at * Return: index I of individual struct iovec which contains the byte at @skip
* @vec_offset bytes into the vector (as though all its buffers were * bytes into the vector (as though all its buffers were contiguous).
* contiguous). If @buf_offset is non-NULL, update it to the offset of * If @offset is non-NULL, update it to the offset of that byte within
* that byte within @iov[I] (guaranteed to be less than @iov[I].iov_len) * @iov[I] (guaranteed to be less than @iov[I].iov_len) If the whole
* If the whole vector has <= @vec_offset bytes, return @n. * vector has <= @skip bytes, return @n.
*/ */
size_t iov_skip_bytes(const struct iovec *iov, size_t n, size_t iov_skip_bytes(const struct iovec *iov, size_t n,
size_t vec_offset, size_t *buf_offset) size_t skip, size_t *offset)
{ {
size_t offset = vec_offset, i; size_t off = skip, i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (offset < iov[i].iov_len) if (off < iov[i].iov_len)
break; break;
offset -= iov[i].iov_len; off -= iov[i].iov_len;
} }
if (buf_offset) if (offset)
*buf_offset = offset; *offset = off;
return i; return i;
} }

2
iov.h
View File

@ -19,7 +19,7 @@
#include <string.h> #include <string.h>
size_t iov_skip_bytes(const struct iovec *iov, size_t n, size_t iov_skip_bytes(const struct iovec *iov, size_t n,
size_t vec_offset, size_t *buf_offset); size_t skip, size_t *offset);
size_t iov_from_buf(const struct iovec *iov, size_t iov_cnt, size_t iov_from_buf(const struct iovec *iov, size_t iov_cnt,
size_t offset, const void *buf, size_t bytes); size_t offset, const void *buf, size_t bytes);
size_t iov_to_buf(const struct iovec *iov, size_t iov_cnt, size_t iov_to_buf(const struct iovec *iov, size_t iov_cnt,