The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright 2003-2005 Colin Percival |
| 3 | * All rights reserved |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted providing that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 22 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 23 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 24 | * POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #if 0 |
| 28 | __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.c,v 1.1 2005/08/06 01:59:06 cperciva Exp $"); |
| 29 | #endif |
| 30 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 31 | #include "bspatch.h" |
| 32 | |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 33 | #include <bzlib.h> |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 34 | #include <err.h> |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 35 | #include <fcntl.h> |
Gilad Arnold | 99b5374 | 2013-04-30 09:24:14 -0700 | [diff] [blame] | 36 | #include <inttypes.h> |
Gilad Arnold | 99b5374 | 2013-04-30 09:24:14 -0700 | [diff] [blame] | 37 | #include <stdlib.h> |
| 38 | #include <string.h> |
| 39 | #include <unistd.h> |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 40 | #include <sys/types.h> |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 41 | |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 42 | #include <algorithm> |
| 43 | #include <memory> |
| 44 | #include <limits> |
| 45 | |
Gilad Arnold | 99b5374 | 2013-04-30 09:24:14 -0700 | [diff] [blame] | 46 | #include "extents.h" |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 47 | #include "extents_file.h" |
| 48 | #include "file.h" |
| 49 | #include "file_interface.h" |
Zdenek Behan | 339e0ee | 2010-06-14 12:50:53 -0700 | [diff] [blame] | 50 | |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 51 | namespace { |
Zdenek Behan | 339e0ee | 2010-06-14 12:50:53 -0700 | [diff] [blame] | 52 | |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 53 | int64_t ParseInt64(u_char* buf) { |
| 54 | int64_t y; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 55 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 56 | y = buf[7] & 0x7F; |
| 57 | y = y * 256; |
| 58 | y += buf[6]; |
| 59 | y = y * 256; |
| 60 | y += buf[5]; |
| 61 | y = y * 256; |
| 62 | y += buf[4]; |
| 63 | y = y * 256; |
| 64 | y += buf[3]; |
| 65 | y = y * 256; |
| 66 | y += buf[2]; |
| 67 | y = y * 256; |
| 68 | y += buf[1]; |
| 69 | y = y * 256; |
| 70 | y += buf[0]; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 71 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 72 | if (buf[7] & 0x80) |
| 73 | y = -y; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 74 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 75 | return y; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 78 | } // namespace |
| 79 | |
| 80 | namespace bsdiff { |
| 81 | |
Alex Deymo | a5cff22 | 2015-04-08 14:10:30 -0700 | [diff] [blame] | 82 | int bspatch( |
| 83 | const char* old_filename, const char* new_filename, |
| 84 | const char* patch_filename, |
| 85 | const char* old_extents, const char* new_extents) { |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 86 | FILE* f, *cpf, *dpf, *epf; |
| 87 | BZFILE* cpfbz2, *dpfbz2, *epfbz2; |
| 88 | int cbz2err, dbz2err, ebz2err; |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 89 | ssize_t bzctrllen, bzdatalen; |
| 90 | u_char header[32], buf[8]; |
| 91 | u_char* new_buf; |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 92 | off_t ctrl[3]; |
| 93 | off_t lenread; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 94 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 95 | int using_extents = (old_extents != NULL || new_extents != NULL); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 96 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 97 | // Open patch file. |
| 98 | if ((f = fopen(patch_filename, "r")) == NULL) |
| 99 | err(1, "fopen(%s)", patch_filename); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 100 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 101 | // File format: |
| 102 | // 0 8 "BSDIFF40" |
| 103 | // 8 8 X |
| 104 | // 16 8 Y |
| 105 | // 24 8 sizeof(new_filename) |
| 106 | // 32 X bzip2(control block) |
| 107 | // 32+X Y bzip2(diff block) |
| 108 | // 32+X+Y ??? bzip2(extra block) |
| 109 | // with control block a set of triples (x,y,z) meaning "add x bytes |
| 110 | // from oldfile to x bytes from the diff block; copy y bytes from the |
| 111 | // extra block; seek forwards in oldfile by z bytes". |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 112 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 113 | // Read header. |
| 114 | if (fread(header, 1, 32, f) < 32) { |
| 115 | if (feof(f)) |
| 116 | errx(1, "Corrupt patch\n"); |
| 117 | err(1, "fread(%s)", patch_filename); |
| 118 | } |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 119 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 120 | // Check for appropriate magic. |
| 121 | if (memcmp(header, "BSDIFF40", 8) != 0) |
| 122 | errx(1, "Corrupt patch\n"); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 123 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 124 | // Read lengths from header. |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 125 | uint64_t oldsize, newsize; |
| 126 | bzctrllen = ParseInt64(header + 8); |
| 127 | bzdatalen = ParseInt64(header + 16); |
| 128 | int64_t signed_newsize = ParseInt64(header + 24); |
| 129 | newsize = signed_newsize; |
| 130 | if ((bzctrllen < 0) || (bzdatalen < 0) || (signed_newsize < 0)) |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 131 | errx(1, "Corrupt patch\n"); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 132 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 133 | // Close patch file and re-open it via libbzip2 at the right places. |
| 134 | if (fclose(f)) |
| 135 | err(1, "fclose(%s)", patch_filename); |
| 136 | if ((cpf = fopen(patch_filename, "r")) == NULL) |
| 137 | err(1, "fopen(%s)", patch_filename); |
| 138 | if (fseek(cpf, 32, SEEK_SET)) |
| 139 | err(1, "fseeko(%s, %lld)", patch_filename, (long long)32); |
| 140 | if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL) |
| 141 | errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err); |
| 142 | if ((dpf = fopen(patch_filename, "r")) == NULL) |
| 143 | err(1, "fopen(%s)", patch_filename); |
| 144 | if (fseek(dpf, 32 + bzctrllen, SEEK_SET)) |
| 145 | err(1, "fseeko(%s, %lld)", patch_filename, (long long)(32 + bzctrllen)); |
| 146 | if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL) |
| 147 | errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err); |
| 148 | if ((epf = fopen(patch_filename, "r")) == NULL) |
| 149 | err(1, "fopen(%s)", patch_filename); |
| 150 | if (fseek(epf, 32 + bzctrllen + bzdatalen, SEEK_SET)) |
| 151 | err(1, "fseeko(%s, %lld)", patch_filename, |
| 152 | (long long)(32 + bzctrllen + bzdatalen)); |
| 153 | if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL) |
| 154 | errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 155 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 156 | // Open input file for reading. |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 157 | std::unique_ptr<FileInterface> old_file = File::FOpen(old_filename, O_RDONLY); |
| 158 | if (!old_file) |
| 159 | err(1, "Error opening the old filename"); |
| 160 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 161 | if (using_extents) { |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 162 | std::vector<ex_t> parsed_old_extents; |
| 163 | if (!ParseExtentStr(old_extents, &parsed_old_extents)) |
| 164 | errx(1, "Error parsing the old extents"); |
| 165 | old_file.reset(new ExtentsFile(std::move(old_file), parsed_old_extents)); |
| 166 | } |
| 167 | |
| 168 | if (!old_file->GetSize(&oldsize)) |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 169 | err(1, "cannot obtain the size of %s", old_filename); |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 170 | uint64_t old_file_pos = 0; |
Gilad Arnold | 99b5374 | 2013-04-30 09:24:14 -0700 | [diff] [blame] | 171 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 172 | if ((new_buf = static_cast<u_char*>(malloc(newsize + 1))) == NULL) |
| 173 | err(1, NULL); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 174 | |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 175 | // The oldpos can be negative, but the new pos is only incremented linearly. |
| 176 | int64_t oldpos = 0; |
| 177 | uint64_t newpos = 0; |
Sen Jiang | d87c835 | 2015-11-20 16:14:36 -0800 | [diff] [blame^] | 178 | std::vector<u_char> old_buf(1024 * 1024); |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 179 | while (newpos < newsize) { |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 180 | int64_t i, j; |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 181 | // Read control data. |
| 182 | for (i = 0; i <= 2; i++) { |
| 183 | lenread = BZ2_bzRead(&cbz2err, cpfbz2, buf, 8); |
| 184 | if ((lenread < 8) || ((cbz2err != BZ_OK) && (cbz2err != BZ_STREAM_END))) |
| 185 | errx(1, "Corrupt patch\n"); |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 186 | ctrl[i] = ParseInt64(buf); |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 187 | }; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 188 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 189 | // Sanity-check. |
| 190 | if (ctrl[0] < 0 || ctrl[1] < 0) |
| 191 | errx(1, "Corrupt patch\n"); |
Doug Zongker | 4d05479 | 2014-05-13 08:37:06 -0700 | [diff] [blame] | 192 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 193 | // Sanity-check. |
| 194 | if (newpos + ctrl[0] > newsize) |
| 195 | errx(1, "Corrupt patch\n"); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 196 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 197 | // Read diff string. |
| 198 | lenread = BZ2_bzRead(&dbz2err, dpfbz2, new_buf + newpos, ctrl[0]); |
| 199 | if ((lenread < ctrl[0]) || |
| 200 | ((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END))) |
| 201 | errx(1, "Corrupt patch\n"); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 202 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 203 | // Add old data to diff string. It is enough to fseek once, at |
| 204 | // the beginning of the sequence, to avoid unnecessary overhead. |
| 205 | j = newpos; |
| 206 | if ((i = oldpos) < 0) { |
| 207 | j -= i; |
| 208 | i = 0; |
| 209 | } |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 210 | // We just checked that |i| is not negative. |
| 211 | if (static_cast<uint64_t>(i) != old_file_pos && !old_file->Seek(i)) |
| 212 | err(1, "error seeking input file to offset %" PRId64, i); |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 213 | if ((old_file_pos = oldpos + ctrl[0]) > oldsize) |
| 214 | old_file_pos = oldsize; |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 215 | |
| 216 | uint64_t chunk_size = old_file_pos - i; |
| 217 | while (chunk_size > 0) { |
| 218 | size_t read_bytes; |
Sen Jiang | d87c835 | 2015-11-20 16:14:36 -0800 | [diff] [blame^] | 219 | size_t bytes_to_read = |
| 220 | std::min(chunk_size, static_cast<uint64_t>(old_buf.size())); |
| 221 | if (!old_file->Read(old_buf.data(), bytes_to_read, &read_bytes)) |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 222 | err(1, "error reading from input file"); |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 223 | if (!read_bytes) |
| 224 | errx(1, "EOF reached while reading from input file"); |
Sen Jiang | d87c835 | 2015-11-20 16:14:36 -0800 | [diff] [blame^] | 225 | // new_buf already has data from diff block, adds old data to it. |
| 226 | for (size_t k = 0; k < read_bytes; k++) |
| 227 | new_buf[j++] += old_buf[k]; |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 228 | chunk_size -= read_bytes; |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 229 | } |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 230 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 231 | // Adjust pointers. |
| 232 | newpos += ctrl[0]; |
| 233 | oldpos += ctrl[0]; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 234 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 235 | // Sanity-check. |
| 236 | if (newpos + ctrl[1] > newsize) |
| 237 | errx(1, "Corrupt patch\n"); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 238 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 239 | // Read extra string. |
| 240 | lenread = BZ2_bzRead(&ebz2err, epfbz2, new_buf + newpos, ctrl[1]); |
| 241 | if ((lenread < ctrl[1]) || |
| 242 | ((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END))) |
| 243 | errx(1, "Corrupt patch\n"); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 244 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 245 | // Adjust pointers. |
| 246 | newpos += ctrl[1]; |
| 247 | oldpos += ctrl[2]; |
| 248 | }; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 249 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 250 | // Close input file. |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 251 | old_file->Close(); |
Gilad Arnold | 99b5374 | 2013-04-30 09:24:14 -0700 | [diff] [blame] | 252 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 253 | // Clean up the bzip2 reads. |
| 254 | BZ2_bzReadClose(&cbz2err, cpfbz2); |
| 255 | BZ2_bzReadClose(&dbz2err, dpfbz2); |
| 256 | BZ2_bzReadClose(&ebz2err, epfbz2); |
| 257 | if (fclose(cpf) || fclose(dpf) || fclose(epf)) |
| 258 | err(1, "fclose(%s)", patch_filename); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 259 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 260 | // Write the new file. |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 261 | std::unique_ptr<FileInterface> new_file = |
| 262 | File::FOpen(new_filename, O_CREAT | O_WRONLY); |
| 263 | if (!new_file) |
| 264 | err(1, "Error opening the new filename %s", new_filename); |
| 265 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 266 | if (using_extents) { |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 267 | std::vector<ex_t> parsed_new_extents; |
| 268 | if (!ParseExtentStr(new_extents, &parsed_new_extents)) |
| 269 | errx(1, "Error parsing the new extents"); |
| 270 | new_file.reset(new ExtentsFile(std::move(new_file), parsed_new_extents)); |
| 271 | } |
| 272 | |
Sen Jiang | d87c835 | 2015-11-20 16:14:36 -0800 | [diff] [blame^] | 273 | u_char* temp_new_buf = new_buf; // new_buf needed for free() |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 274 | while (newsize > 0) { |
| 275 | size_t bytes_written; |
Sen Jiang | d87c835 | 2015-11-20 16:14:36 -0800 | [diff] [blame^] | 276 | if (!new_file->Write(temp_new_buf, newsize, &bytes_written)) |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 277 | err(1, "Error writing new file %s", new_filename); |
| 278 | newsize -= bytes_written; |
Sen Jiang | d87c835 | 2015-11-20 16:14:36 -0800 | [diff] [blame^] | 279 | temp_new_buf += bytes_written; |
Alex Deymo | 437b7af | 2015-10-14 20:13:58 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | if (!new_file->Close()) |
| 283 | err(1, "Error closing new file %s", new_filename); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 284 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 285 | free(new_buf); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 286 | |
Alex Deymo | b870eb5 | 2015-10-14 21:39:04 -0700 | [diff] [blame] | 287 | return 0; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 288 | } |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 289 | |
| 290 | } // namespace bsdiff |