static ssize_t
read_read(struct archive * a, void * cookie, const void ** buffer)
{
	struct multitape_read_internal * d = cookie;
	ssize_t lenread;

	lenread = readtape_read(d, buffer);
	if (lenread < 0) {
		archive_set_error(a, errno, "Error reading archive");
		return (ARCHIVE_FATAL);
	} else
		return (lenread);
}
示例#2
0
文件: tape.c 项目: lornix/tarsnap
/*
 * Read the tape and write to stdout.
 */
void
tarsnap_mode_r(struct bsdtar *bsdtar)
{
	TAPE_R * d;
	const void * buf;
	ssize_t lenread;
	size_t writelen;

	/* Open the tape. */
	if ((d = readtape_open(bsdtar->machinenum,
	    bsdtar->tapenames[0])) == NULL)
		goto err1;

	/* Loop until we have an error or EOF. */
	do {
		lenread = readtape_read(d, &buf);

		/* Error? */
		if (lenread < 0)
			goto err2;

		/* EOF? */
		if (lenread == 0)
			break;

		/* Output data to stdout. */
		writelen = (size_t)(lenread);
		if (fwrite(buf, 1, writelen, stdout) != writelen)
			goto err2;
	} while (1);

	/* We're done!  Close the tape. */
	if (readtape_close(d))
		goto err1;

	/* Success! */
	return;

err2:
	readtape_close(d);

err1:
	/* Failure! */
	bsdtar_warnc(bsdtar, 0, "Error reading archive");
	exit(1);
}