diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-01-04 16:32:21 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-01-04 16:32:21 +0000 |
commit | ee2aeefa170b9806e719723f94ba933c90a9ae8b (patch) | |
tree | 6b71bc492d8801238eb29a4529f5f7b53af9d03c /src | |
parent | cdb1f983a89439ad11d51fe96fc5838cca9d1b3f (diff) | |
download | skalibs-ee2aeefa170b9806e719723f94ba933c90a9ae8b.tar.xz |
Add siovec doc, fix siovec_trunc, credit Ermine
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libstddjb/siovec_trunc.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/libstddjb/siovec_trunc.c b/src/libstddjb/siovec_trunc.c index d71f9d9..621e55f 100644 --- a/src/libstddjb/siovec_trunc.c +++ b/src/libstddjb/siovec_trunc.c @@ -6,13 +6,13 @@ unsigned int siovec_trunc (struct iovec *v, unsigned int n, size_t len) { size_t w = siovec_len(v, n) ; - unsigned int i = n ; if (w < len) return n ; len = w - len ; - while (len && i--) + while (n && len) { - w = len > v[i].iov_len ? v[i].iov_len : len ; - v[i].iov_len -= w ; len -= w ; + w = len > v[n-1].iov_len ? v[n-1].iov_len : len ; + v[n-1].iov_len -= w ; len -= w ; + if (!v[n-1].iov_len) n-- ; } - return i ; + return n ; } |