diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-03-02 12:57:16 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-03-02 12:57:16 -0500 |
commit | 64321c2a6f08cad8ebafafe1b09a913d16a1b0e2 (patch) | |
tree | 437fecdf02946559ad1aa1f4a8deb226bac3832e /util.c | |
parent | b2a19334ef6906cefe1b3ca0e3d5d726d24bf1d3 (diff) |
gracefully handle config errors
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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; +} |