Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practicum1 / cmp.c
diff options
context:
space:
mode:
1 files changed, 21 insertions, 0 deletions
-rw-r--r--Year 3/System programming/Practicum1/cmp.c21
diff --git a/Year 3/System programming/Practicum1/cmp.c b/Year 3/System programming/Practicum1/cmp.c
new file mode 100644
index 0000000..4d12458
--- /dev/null
+++ b/Year 3/System programming/Practicum1/cmp.c
@@ -0,0 +1,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;
+}