/* The IO vectors must have the same structure (same length of all parts). A typical usage is to compare vectors created with qemu_iovec_clone(). */
ssize_t qemu_iovec_compare(QEMUIOVector *a, QEMUIOVector *b)
/* The IO vectors must have the same structure (same length of all parts). A typical usage is to compare vectors created with qemu_iovec_clone(). */
ssize_t qemu_iovec_compare(QEMUIOVector *a, QEMUIOVector *b)
{
    int i;
    ssize_t offset = 0;
    assert(a->niov == b->niov);
    for (i = 0; i < a->niov; i++) {
        size_t len = 0;
        uint8_t *p = (uint8_t *)a->iov[i].iov_base;
        uint8_t *q = (uint8_t *)b->iov[i].iov_base;
        assert(a->iov[i].iov_len == b->iov[i].iov_len);
        while (len < a->iov[i].iov_len && *p++ == *q++) {
            len++;
        }
        offset += len;
        if (len != a->iov[i].iov_len) {
            return offset;
        }
    }
    return -1;
}