From 80e0d719c07ea11aeca858dfc3d9468fc63fc92b Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Thu, 28 Apr 2011 00:41:55 +0200 Subject: idevicebackup2: Use fread/fwrite for copy operation to speed it up --- tools/idevicebackup2.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c index fbe02f8..5ac214e 100644 --- a/tools/idevicebackup2.c +++ b/tools/idevicebackup2.c @@ -968,7 +968,8 @@ static void mb2_handle_make_directory(plist_t message, const char *backup_dir) static void mb2_copy_file_by_path(const gchar *src, const gchar *dst) { FILE *from, *to; - char ch; + char buf[BUFSIZ]; + size_t length; /* open source file */ if ((from = fopen(src, "rb")) == NULL) { @@ -983,19 +984,8 @@ static void mb2_copy_file_by_path(const gchar *src, const gchar *dst) } /* copy the file */ - while(!feof(from)) { - ch = fgetc(from); - if(ferror(from)) { - printf("Error reading source file.\n"); - break; - } - if(!feof(from)) - fputc(ch, to); - - if(ferror(to)) { - printf("Error writing destination file.\n"); - break; - } + while ((length = fread(buf, 1, BUFSIZ, from)) != 0) { + fwrite(buf, 1, length, to); } if(fclose(from) == EOF) { -- cgit v1.1-32-gdbae