public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob 38a8e75660210a1f0d6929e5f7de23b23b56fa8a 1846 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
 
// SPDX-License-Identifier: GPL-2.0-or-later

/* some parts copied from QEMU util/iov.c */

#include <sys/socket.h>
#include "util.h"
#include "iov.h"

size_t iov_from_buf_full(const struct iovec *iov, unsigned int iov_cnt,
			 size_t offset, const void *buf, size_t bytes)
{
	size_t done;
	unsigned int i;
	for (i = 0, done = 0; (offset || done < bytes) && i < iov_cnt; i++) {
		if (offset < iov[i].iov_len) {
			size_t len = MIN(iov[i].iov_len - offset, bytes - done);
			memcpy((char *)iov[i].iov_base + offset, (char *)buf + done, len);
			done += len;
			offset = 0;
		} else {
			offset -= iov[i].iov_len;
		}
	}
	return done;
}

size_t iov_to_buf_full(const struct iovec *iov, const unsigned int iov_cnt,
		       size_t offset, void *buf, size_t bytes)
{
	size_t done;
	unsigned int i;
	for (i = 0, done = 0; (offset || done < bytes) && i < iov_cnt; i++) {
		if (offset < iov[i].iov_len) {
			size_t len = MIN(iov[i].iov_len - offset, bytes - done);
			memcpy((char *)buf + done, (char *)iov[i].iov_base + offset, len);
			done += len;
			offset = 0;
		} else {
			offset -= iov[i].iov_len;
		}
	}
	return done;
}

size_t iov_size(const struct iovec *iov, const unsigned int iov_cnt)
{
	size_t len;
	unsigned int i;

	len = 0;
	for (i = 0; i < iov_cnt; i++) {
		len += iov[i].iov_len;
	}
	return len;
}

unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt,
		  const struct iovec *iov, unsigned int iov_cnt,
		  size_t offset, size_t bytes)
{
	size_t len;
	unsigned int i, j;
	for (i = 0, j = 0;
		 i < iov_cnt && j < dst_iov_cnt && (offset || bytes); i++) {
		if (offset >= iov[i].iov_len) {
			offset -= iov[i].iov_len;
			continue;
		}
		len = MIN(bytes, iov[i].iov_len - offset);

		dst_iov[j].iov_base = (char *)iov[i].iov_base + offset;
		dst_iov[j].iov_len = len;
		j++;
		bytes -= len;
		offset = 0;
	}
	return j;
}

debug log:

solving 38a8e75 ...
found 38a8e75 in https://archives.passt.top/passt-dev/20240202141151.3762941-2-lvivier@redhat.com/

applying [1/1] https://archives.passt.top/passt-dev/20240202141151.3762941-2-lvivier@redhat.com/
diff --git a/iov.c b/iov.c
new file mode 100644
index 000000000000..38a8e7566021

Checking patch iov.c...
Applied patch iov.c cleanly.

index at:
100644 38a8e75660210a1f0d6929e5f7de23b23b56fa8a	iov.c

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).