api.c
off_t tcmu_compare_with_iovec(void *mem, struct iovec *iovec, size_t size)
{
	off_t mem_off;
	int ret;

	mem_off = 0;
	while (size) {
		size_t part = min(size, iovec->iov_len);

		ret = memcmp(mem + mem_off, iovec->iov_base, part);
		if (ret) {
			size_t pos;
			char *spos = mem + mem_off;
			char *dpos = iovec->iov_base;

			/*
			 * Data differed, this is assumed to be 'rare'
			 * so use a much more expensive byte-by-byte
			 * comparison to find out at which offset the
			 * data differs.
			 */
			for (pos = 0; pos < part && *spos++ == *dpos++;
			     pos++)
				;

			return pos + mem_off;
		}

		size -= part;
		mem_off += part;
		iovec++;
	}

	return -1;
}
/*
 * Returns location of first mismatch between bytes in mem and the iovec.
 * If they are the same, return -1.
 */
Returns location of first mismatch between bytes in mem and the iovec.
If they are the same, return -1.
Returns location of first mismatch between bytes in mem and the iovec . If they are the same return - 1 .
off_t tcmu_compare_with_iovec(void *mem, struct iovec *iovec, size_t size)
{
	off_t mem_off;
	int ret;
	mem_off = 0;
	while (size) {
		size_t part = min(size, iovec->iov_len);
		ret = memcmp(mem + mem_off, iovec->iov_base, part);
		if (ret) {
			size_t pos;
			char *spos = mem + mem_off;
			char *dpos = iovec->iov_base;
			for (pos = 0; pos < part && *spos++ == *dpos++;
			     pos++)
				;
			return pos + mem_off;
		}
		size -= part;
		mem_off += part;
		iovec++;
	}
	return -1;
}
off_t tcmu_compare_with_iovec ( void * mem , struct iovec * iovec , size_t size ) { off_t mem_off ; int ret ; mem_off = 0 ; while ( size ) { size_t part = min ( size , iovec -> iov_len ) ; ret = memcmp ( mem + mem_off , iovec -> iov_base , part ) ; if ( ret ) { size_t pos ; char * spos = mem + mem_off ; char * dpos = iovec -> iov_base ; for ( pos = 0 ; pos < part && * spos ++ == * dpos ++ ; pos ++ ) ; return pos + mem_off ; } size -= part ; mem_off += part ; iovec ++ ; } return -1 ; }
Returns location of first mismatch between bytes in mem and the iovec.
Returns location of first mismatch between bytes in mem and the iovec .
/*
			 * Data differed, this is assumed to be 'rare'
			 * so use a much more expensive byte-by-byte
			 * comparison to find out at which offset the
			 * data differs.
			 */