Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practicum1 / cmp.c
blob: 4d12458c2c468ca0f4a4e73b394f055275d1a598 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
	int f1 = open(argv[1], O_RDONLY);
	int f2 = open(argv[2], O_RDONLY);
	if (f1 == -1 || f2 == -1) return 2;

	char buf1;
	char buf2;
	int status = 0;
	while (status == 0 && (read(f1, &buf1, 1) || read(f2, &buf2, 1))) {
		if (buf1 != buf2) status = 1;
	}
	close(f1);
	close(f2);
	return status;
}