Files
zinnia/include/zinnia/iovec.h
T
2026-10-19 20:03:05 +02:00

38 lines
1.1 KiB
C

// SPDX-License-Identifier: ISC
#pragma once
#include <zinnia/errno.h>
#include <zinnia/usercopy.h>
#include <zinnia/utils.h>
#include <stddef.h>
#include <uapi/uio.h>
typedef struct __iovec iovec_t;
typedef struct {
iovec_t* iovecs;
size_t iovecs_len;
size_t total_len;
size_t total_offset;
size_t current_idx;
size_t current_offset;
// Whether the iovecs point to user memory.
bool user;
} iovec_iter_t;
static inline size_t iovec_iter_len(iovec_iter_t* iter) {
return iter->total_len - iter->total_offset;
}
// Creates an iovec iterator over kernel memory.
iovec_iter_t iovec_iter_kernel(iovec_t* iovecs, size_t count);
// Copies up to `len` bytes from `src` into the iterator and advances it.
// Returns the amount of bytes actually copied in `out_copied`.
errno_t iovec_iter_copy_to(iovec_iter_t* iter, const void* src, size_t len, size_t* out_copied);
// Copies up to `len` bytes out of the iterator into `dst` and advances it.
// Returns the amount of bytes actually copied in `out_copied`.
errno_t iovec_iter_copy_from(iovec_iter_t* iter, void* dst, size_t len, size_t* out_copied);