summaryrefslogtreecommitdiffstats
path: root/src/ipsw.c
diff options
context:
space:
mode:
authorGravatar BALATON Zoltan2014-10-17 00:25:26 +0200
committerGravatar BALATON Zoltan2014-10-21 01:15:37 +0200
commitc5aef53c60055d9a18349e6fa8b8f135fb89f046 (patch)
tree4379d4169c20d15b3ad5431a44ff1489475113da /src/ipsw.c
parent9d44bcf451bf295ee5334233d77a7e80867df999 (diff)
downloadidevicerestore-c5aef53c60055d9a18349e6fa8b8f135fb89f046.tar.gz
idevicerestore-c5aef53c60055d9a18349e6fa8b8f135fb89f046.tar.bz2
Fix handling of files larger than 2GB on 32bit systems
Diffstat (limited to 'src/ipsw.c')
-rw-r--r--src/ipsw.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/ipsw.c b/src/ipsw.c
index 9f24784..061d00d 100644
--- a/src/ipsw.c
+++ b/src/ipsw.c
@@ -87,6 +87,7 @@ int ipsw_get_file_size(const char* ipsw, const char* infile, off_t* size) {
}
int ipsw_extract_to_file(const char* ipsw, const char* infile, const char* outfile) {
+ int ret = 0;
ipsw_archive* archive = ipsw_open(ipsw);
if (archive == NULL || archive->zip == NULL) {
error("ERROR: Invalid archive\n");
@@ -125,27 +126,26 @@ int ipsw_extract_to_file(const char* ipsw, const char* infile, const char* outfi
return -1;
}
- int i = 0;
- int size = 0;
- int bytes = 0;
- int count = 0;
- double progress = 0;
+ off_t i, bytes = 0;
+ int count, size = BUFSIZE;
+ double progress;
for(i = zstat.size; i > 0; i -= count) {
if (i < BUFSIZE)
size = i;
- else
- size = BUFSIZE;
count = zip_fread(zfile, buffer, size);
if (count < 0) {
error("ERROR: zip_fread: %s\n", infile);
- zip_fclose(zfile);
- free(buffer);
- return -1;
+ ret = -1;
+ break;
+ }
+ if (fwrite(buffer, 1, count, fd) != count) {
+ error("ERROR: frite: %s\n", outfile);
+ ret = -1;
+ break;
}
- fwrite(buffer, 1, count, fd);
bytes += size;
- progress = ((double) bytes/ (double) zstat.size) * 100.0;
+ progress = ((double)bytes / (double)zstat.size) * 100.0;
print_progress_bar(progress);
}
@@ -153,7 +153,7 @@ int ipsw_extract_to_file(const char* ipsw, const char* infile, const char* outfi
zip_fclose(zfile);
ipsw_close(archive);
free(buffer);
- return 0;
+ return ret;
}
int ipsw_file_exists(const char* ipsw, const char* infile)