summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2011-04-28 00:41:55 +0200
committerGravatar Martin Szulecki2011-04-28 00:41:55 +0200
commit80e0d719c07ea11aeca858dfc3d9468fc63fc92b (patch)
tree43af4dc3e7ad9ef3afedd0dc4dc6a2dc51b8e6ad
parentae730c3c9105f6a9b9bc2fe0944edce45c05071e (diff)
downloadlibimobiledevice-80e0d719c07ea11aeca858dfc3d9468fc63fc92b.tar.gz
libimobiledevice-80e0d719c07ea11aeca858dfc3d9468fc63fc92b.tar.bz2
idevicebackup2: Use fread/fwrite for copy operation to speed it up
-rw-r--r--tools/idevicebackup2.c18
1 files 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) {