diff options
| author | 2011-04-28 00:41:55 +0200 | |
|---|---|---|
| committer | 2011-04-28 00:41:55 +0200 | |
| commit | 80e0d719c07ea11aeca858dfc3d9468fc63fc92b (patch) | |
| tree | 43af4dc3e7ad9ef3afedd0dc4dc6a2dc51b8e6ad /tools/idevicebackup2.c | |
| parent | ae730c3c9105f6a9b9bc2fe0944edce45c05071e (diff) | |
| download | libimobiledevice-80e0d719c07ea11aeca858dfc3d9468fc63fc92b.tar.gz libimobiledevice-80e0d719c07ea11aeca858dfc3d9468fc63fc92b.tar.bz2 | |
idevicebackup2: Use fread/fwrite for copy operation to speed it up
Diffstat (limited to 'tools/idevicebackup2.c')
| -rw-r--r-- | tools/idevicebackup2.c | 18 |
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) | |||
| 968 | static void mb2_copy_file_by_path(const gchar *src, const gchar *dst) | 968 | static void mb2_copy_file_by_path(const gchar *src, const gchar *dst) |
| 969 | { | 969 | { |
| 970 | FILE *from, *to; | 970 | FILE *from, *to; |
| 971 | char ch; | 971 | char buf[BUFSIZ]; |
| 972 | size_t length; | ||
| 972 | 973 | ||
| 973 | /* open source file */ | 974 | /* open source file */ |
| 974 | if ((from = fopen(src, "rb")) == NULL) { | 975 | if ((from = fopen(src, "rb")) == NULL) { |
| @@ -983,19 +984,8 @@ static void mb2_copy_file_by_path(const gchar *src, const gchar *dst) | |||
| 983 | } | 984 | } |
| 984 | 985 | ||
| 985 | /* copy the file */ | 986 | /* copy the file */ |
| 986 | while(!feof(from)) { | 987 | while ((length = fread(buf, 1, BUFSIZ, from)) != 0) { |
| 987 | ch = fgetc(from); | 988 | fwrite(buf, 1, length, to); |
| 988 | if(ferror(from)) { | ||
| 989 | printf("Error reading source file.\n"); | ||
| 990 | break; | ||
| 991 | } | ||
| 992 | if(!feof(from)) | ||
| 993 | fputc(ch, to); | ||
| 994 | |||
| 995 | if(ferror(to)) { | ||
| 996 | printf("Error writing destination file.\n"); | ||
| 997 | break; | ||
| 998 | } | ||
| 999 | } | 989 | } |
| 1000 | 990 | ||
| 1001 | if(fclose(from) == EOF) { | 991 | if(fclose(from) == EOF) { |
