/* Reduce an iovec's length in-place. Return the resulting number of segments  */
unsigned long iov_shorten(struct iovec *iov, unsigned long nr_segs, size_t to)
/* Reduce an iovec's length in-place. Return the resulting number of segments  */
unsigned long iov_shorten(struct iovec *iov, unsigned long nr_segs, size_t to)
{
	unsigned long seg = 0;
	size_t len = 0;
	while (seg < nr_segs) {
		seg++;
		if (len + iov->iov_len >= to) {
			iov->iov_len = to - len;
			break;
		}
		len += iov->iov_len;
		iov++;
	}
	return seg;
}