rem: curr_written  += put; total_written += put;  if (curr_written >= chunk_size) {
add: if (curr_written >= chunk_size) {
context: chop_file (int fdin, char *fname, off_t fsize)	{	const off_t chunk_size = KBytesPerChunk * 1024;  // max bytes written to any output file		bool open_next_file = true;  // when to open a new output file	char fnameN[256];            // name of the current output file (file01, file02, etc.)	int  index = 0;              // used to generate the next output file name	int  fdout;                  // output file descriptor	ssize_t got;                 // size of the current data block -- i.e. from the last read()	ssize_t put;                 // number of bytes just written   -- i.e. from the last write()	ssize_t needed;              // how many bytes we can safely write to the current output file	ssize_t avail;               // how many bytes we can safely grab from the current data block	off_t   curr_written;        // number of bytes written to the current output file	off_t   total_written = 0;   // total bytes written out to all output files			char *beg = Block;  // pointer to the beginning of the block data to be written out	char *end = Block;  // end of the current block (init to beginning to force first block read)		printf ("Chopping up %s into %d kbyte chunks\n", fname, KBytesPerChunk);		while (total_written < fsize)		{		if (beg >= end)			{			// read in another block			got = read (fdin, Block, BLOCKSIZE);			if (got <= 0)				break;						beg = Block;			end = Block + got - 1;			}				if (open_next_file)			{			// start a new output file			sprintf (fnameN,  "%s%02d", fname, index++);			fdout = open (fnameN, O_WRONLY|O_CREAT);			if (fdout < 0)				{				fprintf (stderr, "unable to create chunk file '%s': %s\n", fnameN, strerror (errno));				return;				}			curr_written = 0;			open_next_file = false;			}				needed = chunk_size - curr_written;		avail  = end - beg + 1;		if (needed > avail)			needed = avail;		if (needed > 0)			{			put = write (fdout, beg, needed);			beg += put;			}				curr_written  += put;		total_written += put;				if (curr_written >= chunk_size)			{			// the current output file is full			close (fdout);			open_next_file = true;			}		}		// close up the last output file	close (fdout);	}