From 2a6f8bcca77ae7391a8943a3791be2fbb98a918b Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Wed, 28 Feb 2024 12:52:00 +1100 Subject: iov: add some functions to manage iovec Introduce functions to copy to/from a buffer from/to an iovec array, to compute data length in in bytes of an iovec and to copy memory from an iovec to another. iov_from_buf(), iov_to_buf(), iov_size(), iov_copy(). Signed-off-by: Laurent Vivier Message-ID: <20240217150725.661467-2-lvivier@redhat.com> [dwg: Small changes to suppress cppcheck warnings] Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- iov.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 iov.h (limited to 'iov.h') diff --git a/iov.h b/iov.h new file mode 100644 index 0000000..ee35a75 --- /dev/null +++ b/iov.h @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * iov.c - helpers for using (partial) iovecs. + * + * Copyrigh Red Hat + * Author: Laurent Vivier + * + * This file also contains code originally from QEMU include/qemu/iov.h: + * + * Author(s): + * Amit Shah + * Michael Tokarev + */ + +#ifndef IOVEC_H +#define IOVEC_H + +#include +#include + +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, + size_t offset, void *buf, size_t bytes); +size_t iov_size(const struct iovec *iov, size_t iov_cnt); +unsigned iov_copy(struct iovec *dst_iov, size_t dst_iov_cnt, + const struct iovec *iov, size_t iov_cnt, + size_t offset, size_t bytes); +#endif /* IOVEC_H */ -- cgit v1.2.3