summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/util.c b/util.c
index f99524d..632bd0e 100644
--- a/util.c
+++ b/util.c
@@ -300,3 +300,23 @@ static void change_directory(char const *path) {
#endif
}
+// returns true on success
+static bool copy_file(char const *src, char const *dst) {
+ bool success = false;
+ FILE *src_file = fopen(src, "rb");
+ if (src_file) {
+ FILE *dst_file = fopen(dst, "wb");
+ if (dst_file) {
+ char buf[1024];
+ while (1) {
+ size_t count = fread(buf, 1, sizeof buf, src_file);
+ fwrite(buf, 1, count, dst_file);
+ if (count < sizeof buf) break;
+ }
+ success = !ferror(src_file) && !ferror(dst_file);
+ fclose(dst_file);
+ }
+ fclose(src_file);
+ }
+ return success;
+}