diff options
author | makefunstuff <[email protected]> | 2024-07-13 22:04:48 +0200 |
---|---|---|
committer | makefunstuff <[email protected]> | 2024-07-13 22:04:48 +0200 |
commit | 714036825c38be947eb88a82c02425d7932d2919 (patch) | |
tree | c6723bd239fa5cc93b78ef9e9b7ba5576f708db1 /csrc/cp.c | |
parent | 9b9e63476616a123eb4d00f87f677ef2d9478897 (diff) | |
download | tinkerbunk-714036825c38be947eb88a82c02425d7932d2919.tar.gz |
upd
Diffstat (limited to '')
-rw-r--r-- | csrc/cp.c | 28 |
1 files changed, 28 insertions, 0 deletions
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 <stdio.h> + +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; +} |