From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 518D65A0274 for ; Fri, 1 Mar 2024 05:06:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1709266011; bh=/pCoFHAcXQREHMvtETPT5KHwnUOsHjzgxnYeRMaJKI4=; h=From:To:Cc:Subject:Date:From; b=qWkul7wJQsAxutcMbJW3/CDtvgLo9mk+vrPOJz+433+GUkPijdFgfg7vDe7k4dbI1 b9fE/AigCVzqdQM2jJQr3Ey8rlWH5/T9W9zIxDP3ThF+pH11ZmHMT/NTTtkCjVeC24 re0wao266JUA2cqyOD6RIsRvVxlwESHS1SAzS+BCpe9JCN/blp376C3TOsF88GLt5B fXImPtxG2uN4lXbCDyfUy9GjV6DTBCIurPDHZeSVLV8jaBCuIKuqyuVqNr9dPkxsW4 HQ5Zn5o5MDli8oNtcnNlm+8p0R0QpD16OOckx/oHqephLQVrohDHOJGXqdpFyTWf4d Lq+10leAiQaBA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TmF0C0Z7dz4wcY; Fri, 1 Mar 2024 15:06:51 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH] iov: Improve documentation of iov_skip_bytes() Date: Fri, 1 Mar 2024 15:06:44 +1100 Message-ID: <20240301040644.3680145-1-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: PIODUZ4YZGLDNMUGDYI2MWEWEZQGPZH7 X-Message-ID-Hash: PIODUZ4YZGLDNMUGDYI2MWEWEZQGPZH7 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- iov.c | 28 ++++++++++++++-------------- iov.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/iov.c b/iov.c index e3312628..8e850180 100644 --- a/iov.c +++ b/iov.c @@ -26,31 +26,31 @@ #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 * @n: Number of entries in @iov - * @vec_offset: Total byte offset into the IO vector - * @buf_offset: Offset into a single buffer of the IO vector + * @skip: Number of leading bytes of @iov to skip + * @offset: Offset of first unskipped byte in its @iov entry * - * Return: index I of individual struct iovec which contains the byte at - * @vec_offset bytes into the vector (as though all its buffers were - * contiguous). If @buf_offset is non-NULL, update it to the offset of - * that byte within @iov[I] (guaranteed to be less than @iov[I].iov_len) - * If the whole vector has <= @vec_offset bytes, return @n. + * Return: index I of individual struct iovec which contains the byte at @skip + * bytes into the vector (as though all its buffers were contiguous). + * If @offset is non-NULL, update it to the offset of that byte within + * @iov[I] (guaranteed to be less than @iov[I].iov_len) If the whole + * vector has <= @skip bytes, return @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++) { - if (offset < iov[i].iov_len) + if (off < iov[i].iov_len) break; - offset -= iov[i].iov_len; + off -= iov[i].iov_len; } - if (buf_offset) - *buf_offset = offset; + if (offset) + *offset = off; return i; } diff --git a/iov.h b/iov.h index e1becdea..6058af77 100644 --- a/iov.h +++ b/iov.h @@ -19,7 +19,7 @@ #include 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 offset, const void *buf, size_t bytes); size_t iov_to_buf(const struct iovec *iov, size_t iov_cnt, -- 2.44.0