rem: rd = inSource->Read(buf, rd);
add: rd = inSource->Read(buf, kbuflen);
context: translate_from_tga(BPositionIO *inSource, ssize_t amtread, uint8 *read,	TGATranslatorSettings &settings, uint32 outType,	BPositionIO *outDestination){	TGAFileHeader fileheader;	TGAColorMapSpec mapspec;	TGAImageSpec imagespec;	bool bheaderonly, bdataonly;	bheaderonly = settings.SetGetHeaderOnly();	bdataonly = settings.SetGetDataOnly();	status_t result;	result = identify_tga_header(inSource, NULL, amtread, read,		&fileheader, &mapspec, &imagespec);	if (result != B_OK)		return result;		// if the user wants to translate a TGA to a TGA, easy enough :)		if (outType == B_TGA_FORMAT) {		// write out the TGA headers		if (bheaderonly || (!bheaderonly && !bdataonly)) {			result = write_tga_headers(outDestination, fileheader,				mapspec, imagespec);			if (result != B_OK)				return result;		}		if (bheaderonly)			// if the user only wants the header, 			// bail before it is written			return result;					uint8 buf[1024];		ssize_t rd = inSource->Read(buf, rd);		while (rd > 0) {			outDestination->Write(buf, rd);			rd = inSource->Read(buf, rd);		}		if (rd == 0)			return B_OK;		else			return B_ERROR;		// if translating a TGA to a Be Bitmap	} else if (outType == B_TRANSLATOR_BITMAP) {		TranslatorBitmap bitsHeader;		bitsHeader.magic = B_TRANSLATOR_BITMAP;		bitsHeader.bounds.left = 0;		bitsHeader.bounds.top = 0;		bitsHeader.bounds.right = imagespec.width - 1;		bitsHeader.bounds.bottom = imagespec.height - 1;				// skip over Image ID data (if present)		if (fileheader.idlength > 0)			inSource->Seek(fileheader.idlength, SEEK_CUR);				// read in palette and/or skip non-TGA data							uint8 *ptgapalette = NULL;		if (fileheader.colormaptype == TGA_COLORMAP) {			uint32 nentrybytes;			nentrybytes = mapspec.entrysize / 8;			if (mapspec.entrysize % 8)				nentrybytes++;			ptgapalette = new uint8[nentrybytes * mapspec.length];			inSource->Read(ptgapalette, nentrybytes * mapspec.length);		}		bitsHeader.rowBytes = imagespec.width * 4;		if (fileheader.imagetype != TGA_NOCOMP_BW &&			fileheader.imagetype != TGA_RLE_BW &&			imagespec.descriptor & TGA_DESC_ALPHABITS)			bitsHeader.colors = B_RGBA32;		else			bitsHeader.colors = B_RGB32;		int32 datasize = bitsHeader.rowBytes * imagespec.height;		bitsHeader.dataSize = datasize;						// write out Be's Bitmap header		if (bheaderonly || (!bheaderonly && !bdataonly)) {			if (swap_data(B_UINT32_TYPE, &bitsHeader,				sizeof(TranslatorBitmap), B_SWAP_HOST_TO_BENDIAN) != B_OK)				return B_ERROR;			outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap));		}		if (bheaderonly)			// if the user only wants the header, 			// bail before the data is written			return B_OK;				// write out the actual image data		switch (fileheader.imagetype) {			case TGA_NOCOMP_TRUECOLOR:			case TGA_NOCOMP_BW:				result = translate_from_tganm_to_bits(inSource,					outDestination, imagespec);				break;							case TGA_NOCOMP_COLORMAP:				result = translate_from_tgam_to_bits(inSource,					outDestination, mapspec, imagespec, ptgapalette);				break;							case TGA_RLE_TRUECOLOR:			case TGA_RLE_BW:				result = translate_from_tganmrle_to_bits(inSource,					outDestination, imagespec);				break;							case TGA_RLE_COLORMAP:				result = translate_from_tgamrle_to_bits(inSource,					outDestination, mapspec, imagespec, ptgapalette);				break;							default:				result = B_NO_TRANSLATOR;				break;		}				delete[] ptgapalette;		ptgapalette = NULL;				return result;			} else		return B_NO_TRANSLATOR;}