/* cmp.c - 19 Apr 88  A.J.Travis *//* * Simple file comparison */#include <stdio.h>char buf1[BUFSIZ];char buf2[BUFSIZ];char *bp1, *bp2;int c1, c2;int fd1, fd2;int n1, n2;int n;int main(argc, argv)int argc;char *argv[];{	if (argc != 3) {		fprintf(stderr, "usage: cmp file1 file2\n");		exit(-1);	}	if ((fd1 = open(argv[1], 0)) == -1) {		fprintf(stderr, "cmp: can't open %s\n", argv[1]);		exit(-1);	}	if ((fd2 = open(argv[2], 0)) == -1) {		fprintf(stderr, "cmp: can't open %s\n", argv[2]);		close(fd1);		exit(-1);	}	n = 0;	do {		n1 = read(fd1, buf1, BUFSIZ);		n2 = read(fd2, buf2, BUFSIZ);		bp1 = buf1;		bp2 = buf2;		while ((bp1 < buf1 + n1) & (bp2 < buf2 + n2)) {			if ((c1 = *bp1++ & 0xFF) != (c2 = *bp2++ & 0xFF))				printf("%4X: %02X %02X\n", n, c1, c2);			n++;		}		if (n1 < n2)			printf("cmp: end of file on %s\n", argv[1]);		if (n1 > n2)			printf("cmp: end of file on %s\n", argv[2]);	}	while (n1 > 0 & n1 == n2);	close(fd1);	close(fd2);	exit(0);}