summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-03-02 12:57:16 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-03-02 12:57:16 -0500
commit64321c2a6f08cad8ebafafe1b09a913d16a1b0e2 (patch)
tree437fecdf02946559ad1aa1f4a8deb226bac3832e /util.c
parentb2a19334ef6906cefe1b3ca0e3d5d726d24bf1d3 (diff)
gracefully handle config errors
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;
+}