Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practicum1 / cp.c
diff options
context:
space:
mode:
1 files changed, 20 insertions, 0 deletions
-rw-r--r--Year 3/System programming/Practicum1/cp.c20
diff --git a/Year 3/System programming/Practicum1/cp.c b/Year 3/System programming/Practicum1/cp.c
new file mode 100644
index 0000000..f44e44d
--- /dev/null
+++ b/Year 3/System programming/Practicum1/cp.c
@@ -0,0 +1,20 @@
+#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);
+ if (f1 == -1) return 1;
+ int f2 = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, 0755);
+ if (f2 == -1) return 2;
+
+ char buf;
+ while(read(f1, &buf, 1)) {
+ write(f2, &buf, 1);
+ }
+
+ close(f1);
+ close(f2);
+}