Welcome to little lamb

Code » limb » release » tree

[release] / src / liblimb / siovec.h / siov_memcmp.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 <string.h>
#include <limb/siovec.h>

int
siov_memcmp(const struct iovec *v, unsigned int n, const char *s, size_t len)
{
    int r = (n) ? 0 : (len) ? -1 : 0;

    for (unsigned int i = 0; len && i < n; ++i) {
        if (!v[i].iov_len) continue;

        size_t l = v[i].iov_len >= len ? len : v[i].iov_len;
        r = memcmp(v[i].iov_base, s, l);
        if (r) return r;

        len -= l;
    }

    return (len) ? -1 : r;
}