OLD | NEW |
1 /* | 1 /* |
2 Additional tools for Minizip | 2 Additional tools for Minizip |
3 Code: Xavier Roche '2004 | 3 Code: Xavier Roche '2004 |
4 License: Same as ZLIB (www.gzip.org) | 4 License: Same as ZLIB (www.gzip.org) |
5 */ | 5 */ |
6 | 6 |
7 /* Code */ | 7 /* Code */ |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 24 matching lines...) Expand all Loading... |
35 uLong* bytesRecovered; | 35 uLong* bytesRecovered; |
36 { | 36 { |
37 int err = Z_OK; | 37 int err = Z_OK; |
38 FILE* fpZip = fopen(file, "rb"); | 38 FILE* fpZip = fopen(file, "rb"); |
39 FILE* fpOut = fopen(fileOut, "wb"); | 39 FILE* fpOut = fopen(fileOut, "wb"); |
40 FILE* fpOutCD = fopen(fileOutTmp, "wb"); | 40 FILE* fpOutCD = fopen(fileOutTmp, "wb"); |
41 if (fpZip != NULL && fpOut != NULL) { | 41 if (fpZip != NULL && fpOut != NULL) { |
42 int entries = 0; | 42 int entries = 0; |
43 uLong totalBytes = 0; | 43 uLong totalBytes = 0; |
44 char header[30]; | 44 char header[30]; |
45 char filename[1024]; | 45 char filename[256]; |
46 char extra[1024]; | 46 char extra[1024]; |
47 int offset = 0; | 47 int offset = 0; |
48 int offsetCD = 0; | 48 int offsetCD = 0; |
49 while ( fread(header, 1, 30, fpZip) == 30 ) { | 49 while ( fread(header, 1, 30, fpZip) == 30 ) { |
50 int currentOffset = offset; | 50 int currentOffset = offset; |
51 | 51 |
52 /* File entry */ | 52 /* File entry */ |
53 if (READ_32(header) == 0x04034b50) { | 53 if (READ_32(header) == 0x04034b50) { |
54 unsigned int version = READ_16(header + 4); | 54 unsigned int version = READ_16(header + 4); |
55 unsigned int gpflag = READ_16(header + 6); | 55 unsigned int gpflag = READ_16(header + 6); |
(...skipping 10 matching lines...) Expand all Loading... |
66 /* Header */ | 66 /* Header */ |
67 if (fwrite(header, 1, 30, fpOut) == 30) { | 67 if (fwrite(header, 1, 30, fpOut) == 30) { |
68 offset += 30; | 68 offset += 30; |
69 } else { | 69 } else { |
70 err = Z_ERRNO; | 70 err = Z_ERRNO; |
71 break; | 71 break; |
72 } | 72 } |
73 | 73 |
74 /* Filename */ | 74 /* Filename */ |
75 if (fnsize > 0) { | 75 if (fnsize > 0) { |
76 if (fnsize < sizeof(filename)) { | 76 if (fread(filename, 1, fnsize, fpZip) == fnsize) { |
77 if (fread(filename, 1, fnsize, fpZip) == fnsize) { | 77 if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { |
78 if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { | 78 offset += fnsize; |
79 offset += fnsize; | |
80 } else { | |
81 err = Z_ERRNO; | |
82 break; | |
83 } | |
84 } else { | 79 } else { |
85 err = Z_ERRNO; | 80 err = Z_ERRNO; |
86 break; | 81 break; |
87 } | 82 } |
88 } else { | 83 } else { |
89 err = Z_ERRNO; | 84 err = Z_ERRNO; |
90 break; | 85 break; |
91 } | 86 } |
92 } else { | 87 } else { |
93 err = Z_STREAM_ERROR; | 88 err = Z_STREAM_ERROR; |
94 break; | 89 break; |
95 } | 90 } |
96 | 91 |
97 /* Extra field */ | 92 /* Extra field */ |
98 if (extsize > 0) { | 93 if (extsize > 0) { |
99 if (extsize < sizeof(extra)) { | 94 if (fread(extra, 1, extsize, fpZip) == extsize) { |
100 if (fread(extra, 1, extsize, fpZip) == extsize) { | 95 if (fwrite(extra, 1, extsize, fpOut) == extsize) { |
101 if (fwrite(extra, 1, extsize, fpOut) == extsize) { | 96 offset += extsize; |
102 offset += extsize; | |
103 } else { | |
104 err = Z_ERRNO; | |
105 break; | |
106 } | |
107 } else { | 97 } else { |
108 err = Z_ERRNO; | 98 err = Z_ERRNO; |
109 break; | 99 break; |
110 } | 100 } |
111 } else { | 101 } else { |
112 err = Z_ERRNO; | 102 err = Z_ERRNO; |
113 break; | 103 break; |
114 } | 104 } |
115 } | 105 } |
116 | 106 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 } | 272 } |
283 if (bytesRecovered != NULL) { | 273 if (bytesRecovered != NULL) { |
284 *bytesRecovered = totalBytes; | 274 *bytesRecovered = totalBytes; |
285 } | 275 } |
286 } | 276 } |
287 } else { | 277 } else { |
288 err = Z_STREAM_ERROR; | 278 err = Z_STREAM_ERROR; |
289 } | 279 } |
290 return err; | 280 return err; |
291 } | 281 } |
OLD | NEW |