From 714036825c38be947eb88a82c02425d7932d2919 Mon Sep 17 00:00:00 2001 From: makefunstuff Date: Sat, 13 Jul 2024 23:04:48 +0300 Subject: upd --- csrc/cp.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 csrc/cp.c (limited to 'csrc/cp.c') diff --git a/csrc/cp.c b/csrc/cp.c new file mode 100644 index 0000000..5280bae --- /dev/null +++ b/csrc/cp.c @@ -0,0 +1,28 @@ +#include "cp.h" +#include + +FileStatus copy_file(char *src, char *dst) { + + FILE *source = fopen(src, "rb"); + if (!source) { + return READ_ERROR; + } + + FILE *destination = fopen(dst, "wb"); + if (!destination) { + fclose(source); + return WRITE_ERROR; + } + + char buffer[1024]; + size_t bytes; + + while ((bytes = fread(buffer, 1, sizeof(buffer), source)) > 0) { + fwrite(buffer, 1, bytes, destination); + } + + fclose(source); + fclose(destination); + + return WRITE_OK; +} -- cgit 1.4.1-2-gfad0