Beispiel #1
0
rt_private int run_idr_read (IDR *bu)
{
	RT_GET_CONTEXT
	register char * ptr = bu->i_buf;
	int32 read_size;
	long amount_left;
	register int part_read;
	register int total_read = 0;

	if ((char_read_func ((char *)(&read_size), sizeof (int32))) < sizeof (int32))
		eise_io("Independent retrieve: unable to read buffer size.");

	read_size = ntohl (read_size);
#ifdef DEBUG
	if (read_size > idrs_size (bu))
		print_err_msg(stderr, "Too large %d info for %d buffer\n", read_size, idrs_size (bu));
#endif

	amount_left = read_size;
	while (total_read < read_size) {
		if ((part_read = char_read_func (ptr, amount_left)) <= 0) {
				/* If we read 0 bytes, it means that we reached the end of file,
				 * so we are missing something, instead of going further we stop */
			eio();
		}
		total_read += part_read;
		ptr += part_read;
		amount_left -= part_read;
		}
	return total_read;
}
rt_private size_t parsing_retrieve_read_with_compression (void)
{
	RT_GET_CONTEXT
	void* dcmps_in_ptr = (char *)0;
	void* dcmps_out_ptr = (char *)0;
	lzo_uint dcmps_in_size = 0;
	lzo_uint dcmps_out_size = (lzo_uint) cmp_buffer_size;
	char* ptr = (char *)0;
	int read_size = 0;
	int part_read = 0;
	int l_bytes_read;

	REQUIRE("cmp_buffer_size not too big", cmp_buffer_size <= 0xFFFFFFFF);

	ptr = cmps_general_buffer;
	l_bytes_read = char_read_func ((char *) &read_size, sizeof(int));
	if ((l_bytes_read < 0) || ((size_t) l_bytes_read < sizeof(int))) {
	  eio();
	}

	dcmps_in_size = read_size;

	while (read_size > 0) {
		part_read = char_read_func (ptr, read_size);
		if (part_read <= 0)
				/* If we read 0 bytes, it means that we reached the end of file,
				 * so we are missing something, instead of going further we stop */
			eio();
		read_size -= part_read;
		ptr += part_read;
	}
	
	dcmps_in_ptr = cmps_general_buffer;
	dcmps_out_ptr = general_buffer;
	
	lzo1x_decompress (dcmps_in_ptr, dcmps_in_size,
					dcmps_out_ptr, &dcmps_out_size, NULL);

	CHECK("dcmps_out_size_positive", dcmps_out_size > 0);
	return dcmps_out_size;
}