V9/cmd/strip/fcopy.c

Compare this file to the similar file:
Show the results in this format:

#define BSIZE	4096
#define min(a,b)	((a)<(b) ? (a) : (b))

fcopy(to, from, nbytes)
int to, from; register int nbytes;
{
	char *malloc();
	register char *buf; register int n;

	if (nbytes && (buf = malloc(min(nbytes, BSIZE)))) {
		do {
			n = min(nbytes, BSIZE);
			if (read(from, buf, n) != n) break;
			if (write(to, buf, n) != n) break;
			nbytes -= n;
		} while (nbytes);
		free(buf);
	}
	return nbytes;
}