Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Operating Systems / Pract11 / cp.c
diff options
context:
space:
mode:
Commit2aacf1b28daa876123919f7fab67f2a538864ee6 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-08-24 13:02:16 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-08-24 13:02:16 +0300
Filescf6ba1b6f6028f67cfc549fa5e490b0e508e33fe /Year 2/Operating Systems/Pract11/cp.c
uni-projects-2aacf1b28daa876123919f7fab67f2a538864ee6.tar
uni-projects-2aacf1b28daa876123919f7fab67f2a538864ee6.tar.gz
uni-projects-2aacf1b28daa876123919f7fab67f2a538864ee6.zip
Parent1d1f9e1e713a8b6a786f2b191d8a9db5f1dca79f (diff)
[OS] Added some work I did a while ago
1 files changed, 24 insertions, 0 deletions
-rw-r--r--Year 2/Operating Systems/Pract11/cp.c24
diff --git a/Year 2/Operating Systems/Pract11/cp.c b/Year 2/Operating Systems/Pract11/cp.c
new file mode 100644
index 0000000..044b278
--- /dev/null
+++ b/Year 2/Operating Systems/Pract11/cp.c
@@ -0,0 +1,24 @@
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+const size_t BUF_SIZE = 1024;
+
+int main(int argc, char *argv[]) {
+ if (argc < 3) return 1;
+
+ int fd_from = open(argv[1], O_RDONLY);
+ if (fd_from < 0) return 2;
+
+ int fd_to = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0744);
+ if (fd_to < 0) return 3;
+
+ char buf[BUF_SIZE];
+ size_t actual = read(fd_from, buf, BUF_SIZE);
+ while (actual > 0) {
+ write(fd_to, buf, actual);
+ actual = read(fd_from, buf, BUF_SIZE);
+ }
+ return 0;
+}