#include #include #include #include int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "Wrong argument count!\n"); return 2; } int a = open(argv[1], O_RDONLY); if (a == -1) { perror("Opening the first file failed"); return 2; } int b = open(argv[2], O_RDONLY); if (b == -1) { perror("Opening the second file failed"); close(a); return 2; } char bufA[256], bufB[256]; int cntA, cntB, rv; while (1) { cntA = read(a, bufA, 256); cntB = read(b, bufB, 256); if (cntA != cntB) { printf("Files differ\n"); rv = 1; break; } if (memcmp(bufA, bufB, cntA)) { printf("Files differ\n"); rv = 1; break; } if (cntA <= 0) { printf("Files are identical\n"); rv = 0; break; } } close(a); close(b); return rv; }