int
copyFaxFile(TIFF* tifin, TIFF* tifout)
{
	uint32 row;
	uint32 linesize = TIFFhowmany8(xsize);
	uint16 badrun;
	int ok;
	tifin->tif_rawdatasize = (tmsize_t)TIFFGetFileSize(tifin);
	if (tifin->tif_rawdatasize == 0) {
		TIFFError(tifin->tif_name, "Empty input file");
		return (0);
	}
	tifin->tif_rawdata = _TIFFmalloc(tifin->tif_rawdatasize);
	if (tifin->tif_rawdata == NULL) {
		TIFFError(tifin->tif_name, "Not enough memory");
		return (0);
	}
	if (!ReadOK(tifin, tifin->tif_rawdata, tifin->tif_rawdatasize)) {
		TIFFError(tifin->tif_name, "Read error at scanline 0");
		return (0);
	}
	tifin->tif_rawcp = tifin->tif_rawdata;
	tifin->tif_rawcc = tifin->tif_rawdatasize;
	(*tifin->tif_setupdecode)(tifin);
	(*tifin->tif_predecode)(tifin, (tsample_t) 0);
	tifin->tif_row = 0;
	badfaxlines = 0;
	badfaxrun = 0;
	_TIFFmemset(refbuf, 0, linesize);
	row = 0;
	badrun = 0;
	while (tifin->tif_rawcc > 0) {
		ok = (*tifin->tif_decoderow)(tifin, (tdata_t) rowbuf,
					     linesize, 0);
		if (!ok) {
			badfaxlines++;
			badrun++;
			_TIFFmemcpy(rowbuf, refbuf, linesize);
		} else {
			if (badrun > badfaxrun)
				badfaxrun = badrun;
			badrun = 0;
			_TIFFmemcpy(refbuf, rowbuf, linesize);
		}
		tifin->tif_row++;
		if (TIFFWriteScanline(tifout, rowbuf, row, 0) < 0) {
			fprintf(stderr, "%s: Write error at row %ld.\n",
			    tifout->tif_name, (long) row);
			break;
		}
		row++;
		if (stretch) {
			if (TIFFWriteScanline(tifout, rowbuf, row, 0) < 0) {
				fprintf(stderr, "%s: Write error at row %ld.\n",
				    tifout->tif_name, (long) row);
				break;
			}
			row++;
		}
	}
	if (badrun > badfaxrun)
		badfaxrun = badrun;
	_TIFFfree(tifin->tif_rawdata);
	return (row);
}
['int\ncopyFaxFile(TIFF* tifin, TIFF* tifout)\n{\n\tuint32 row;\n\tuint32 linesize = TIFFhowmany8(xsize);\n\tuint16 badrun;\n\tint ok;\n\ttifin->tif_rawdatasize = (tmsize_t)TIFFGetFileSize(tifin);\n\tif (tifin->tif_rawdatasize == 0) {\n\t\tTIFFError(tifin->tif_name, "Empty input file");\n\t\treturn (0);\n\t}\n\ttifin->tif_rawdata = _TIFFmalloc(tifin->tif_rawdatasize);\n\tif (tifin->tif_rawdata == NULL) {\n\t\tTIFFError(tifin->tif_name, "Not enough memory");\n\t\treturn (0);\n\t}\n\tif (!ReadOK(tifin, tifin->tif_rawdata, tifin->tif_rawdatasize)) {\n\t\tTIFFError(tifin->tif_name, "Read error at scanline 0");\n\t\treturn (0);\n\t}\n\ttifin->tif_rawcp = tifin->tif_rawdata;\n\ttifin->tif_rawcc = tifin->tif_rawdatasize;\n\t(*tifin->tif_setupdecode)(tifin);\n\t(*tifin->tif_predecode)(tifin, (tsample_t) 0);\n\ttifin->tif_row = 0;\n\tbadfaxlines = 0;\n\tbadfaxrun = 0;\n\t_TIFFmemset(refbuf, 0, linesize);\n\trow = 0;\n\tbadrun = 0;\n\twhile (tifin->tif_rawcc > 0) {\n\t\tok = (*tifin->tif_decoderow)(tifin, (tdata_t) rowbuf,\n\t\t\t\t\t     linesize, 0);\n\t\tif (!ok) {\n\t\t\tbadfaxlines++;\n\t\t\tbadrun++;\n\t\t\t_TIFFmemcpy(rowbuf, refbuf, linesize);\n\t\t} else {\n\t\t\tif (badrun > badfaxrun)\n\t\t\t\tbadfaxrun = badrun;\n\t\t\tbadrun = 0;\n\t\t\t_TIFFmemcpy(refbuf, rowbuf, linesize);\n\t\t}\n\t\ttifin->tif_row++;\n\t\tif (TIFFWriteScanline(tifout, rowbuf, row, 0) < 0) {\n\t\t\tfprintf(stderr, "%s: Write error at row %ld.\\n",\n\t\t\t    tifout->tif_name, (long) row);\n\t\t\tbreak;\n\t\t}\n\t\trow++;\n\t\tif (stretch) {\n\t\t\tif (TIFFWriteScanline(tifout, rowbuf, row, 0) < 0) {\n\t\t\t\tfprintf(stderr, "%s: Write error at row %ld.\\n",\n\t\t\t\t    tifout->tif_name, (long) row);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\trow++;\n\t\t}\n\t}\n\tif (badrun > badfaxrun)\n\t\tbadfaxrun = badrun;\n\t_TIFFfree(tifin->tif_rawdata);\n\treturn (row);\n}', 'void*\n_TIFFmalloc(tmsize_t s)\n{\n        if (s == 0)\n                return ((void *) NULL);\n\treturn (malloc((size_t) s));\n}']