#include "gbos.h" /* cmp FILE1 FILE2: report the first byte where two files differ, or say * nothing when they match (like cmp(1), silence means identical). * * After cp/mv/tee/nc there was still no way to check a copy ON the machine - * you had to haul both files to a host. */ void main(void) { char *argv[4]; unsigned char argc = argv_parse(argv, 4); unsigned char a, b; unsigned int off = 0; int ca, cb; if (argc < 2) { puts("usage: cmp FILE1 FILE2"); nl(); sexit(2); } a = open(argv[0], O_READ); if (a > 3) { puts("cmp: cannot open "); puts(argv[0]); nl(); sexit(2); } b = open(argv[1], O_READ); if (b > 3) { puts("cmp: cannot open "); puts(argv[1]); nl(); close(a); sexit(2); } for (;;) { ca = fgetc(a); cb = fgetc(b); if (ca < 0 && cb < 0) break; /* same length, same bytes */ if (ca < 0 || cb < 0) { puts("cmp: EOF on "); puts(ca < 0 ? argv[0] : argv[1]); puts(" after "); putu(off); nl(); close(a); close(b); sexit(1); } if (ca != cb) { puts("differ: byte "); putu(off); nl(); close(a); close(b); sexit(1); } off++; } close(a); close(b); }