static i64 unzip_match(rzip_control *control, void *ss, i64 len, uint32 *cksum, int chunk_bytes)
{
	i64 offset, n, total, cur_pos;
	uchar *buf;

	if (unlikely(len < 0))
		failure_return(("len %lld is negative in unzip_match!\n",len), -1);

	total = 0;
	cur_pos = seekcur_fdout(control);
	if (unlikely(cur_pos == -1))
		fatal_return(("Seek failed on out file in unzip_match.\n"), -1);

	/* Note the offset is in a different format v0.40+ */
	offset = read_vchars(control, ss, 0, chunk_bytes);
	if (unlikely(offset == -1))
		return -1;
	if (unlikely(seekto_fdhist(control, cur_pos - offset) == -1))
		fatal_return(("Seek failed by %d from %d on history file in unzip_match\n",
		      offset, cur_pos), -1);

	n = MIN(len, offset);
	if (unlikely(n < 1))
		fatal_return(("Failed fd history in unzip_match due to corrupt archive\n"), -1);

	buf = (uchar *)malloc(n);
	if (unlikely(!buf))
		fatal_return(("Failed to malloc match buffer of size %lld\n", len), -1);

	if (unlikely(read_fdhist(control, buf, (size_t)n) != (ssize_t)n)) {
		dealloc(buf);
		fatal_return(("Failed to read %d bytes in unzip_match\n", n), -1);
	}

	while (len) {
		n = MIN(len, offset);
		if (unlikely(n < 1))
			fatal_return(("Failed fd history in unzip_match due to corrupt archive\n"), -1);

		if (unlikely(write_1g(control, buf, (size_t)n) != (ssize_t)n)) {
			dealloc(buf);
			fatal_return(("Failed to write %d bytes in unzip_match\n", n), -1);
		}

		if (!HAS_MD5)
			*cksum = CrcUpdate(*cksum, buf, n);
		if (!NO_MD5)
			md5_process_bytes(buf, n, &control->ctx);

		len -= n;
		total += n;
	}

	dealloc(buf);

	return total;
}
static i64 unzip_match(rzip_control *control, void *ss, i64 len, uint32 *cksum, int chunk_bytes)
{
	i64 offset, n, total, cur_pos;
	uchar *buf;

	if (unlikely(len < 0))
		failure_return(("len %lld is negative in unzip_match!\n",len), -1);

	total = 0;
	cur_pos = seekcur_fdout(control);
	if (unlikely(cur_pos == -1))
		fatal_return(("Seek failed on out file in unzip_match.\n"), -1);

	 
	offset = read_vchars(control, ss, 0, chunk_bytes);
	if (unlikely(offset == -1))
		return -1;
	if (unlikely(seekto_fdhist(control, cur_pos - offset) == -1))
		fatal_return(("Seek failed by %d from %d on history file in unzip_match\n",
		      offset, cur_pos), -1);

	n = MIN(len, offset);
	if (unlikely(n < 1))
		fatal_return(("Failed fd history in unzip_match due to corrupt archive\n"), -1);

	buf = (uchar *)malloc(n);
	if (unlikely(!buf))
		fatal_return(("Failed to malloc match buffer of size %lld\n", len), -1);

	if (unlikely(read_fdhist(control, buf, (size_t)n) != (ssize_t)n)) {
		dealloc(buf);
		fatal_return(("Failed to read %d bytes in unzip_match\n", n), -1);
	}

	while (len) {
		n = MIN(len, offset);
		if (unlikely(n < 1))
			fatal_return(("Failed fd history in unzip_match due to corrupt archive\n"), -1);

		if (unlikely(write_1g(control, buf, (size_t)n) != (ssize_t)n)) {
			dealloc(buf);
			fatal_return(("Failed to write %d bytes in unzip_match\n", n), -1);
		}

		if (!HAS_MD5)
			*cksum = CrcUpdate(*cksum, buf, n);
		if (!NO_MD5)
			md5_process_bytes(buf, n, &control->ctx);

		len -= n;
		total += n;
	}

	dealloc(buf);

	return total;
}