Welcome to little lamb

Code » limb » master » tree

[master] / src / liblimb / siovec.h / siov_off.c

/* This file is part of limb                           https://lila.oss/limb
 * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
/* SPDX-License-Identifier: GPL-2.0-only */
#include <errno.h>
#include <limb/siovec.h>

int
siov_off(const struct iovec *v, unsigned int n, size_t off)
{
    for (unsigned int i = 0; i < n; ++i) {
        if (v[i].iov_len > off) return ((char *) v[i].iov_base)[off];
        off -= v[i].iov_len;
    }
    return (errno = EINVAL, -1);
}