1c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project/*- 2c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * Copyright 2003-2005 Colin Percival 3c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * All rights reserved 4c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * 5c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * Redistribution and use in source and binary forms, with or without 6c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * modification, are permitted providing that the following conditions 7c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * are met: 8c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * 1. Redistributions of source code must retain the above copyright 9c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * notice, this list of conditions and the following disclaimer. 10c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright 11c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * notice, this list of conditions and the following disclaimer in the 12c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * documentation and/or other materials provided with the distribution. 13c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * 14c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 18c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 22c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 23c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project * POSSIBILITY OF SUCH DAMAGE. 25c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project */ 26c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 27c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project#if 0 28c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project__FBSDID("$FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.c,v 1.1 2005/08/06 01:59:06 cperciva Exp $"); 29c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project#endif 30c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 31c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project#include <bzlib.h> 32c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project#include <stdlib.h> 33c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project#include <stdio.h> 34c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project#include <string.h> 35c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project#include <err.h> 36c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project#include <unistd.h> 37c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project#include <fcntl.h> 38c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project#include <sys/types.h> // android 39c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 40c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Projectstatic off_t offtin(u_char *buf) 41c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project{ 42c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project off_t y; 43c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 44c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project y=buf[7]&0x7F; 45c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project y=y*256;y+=buf[6]; 46c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project y=y*256;y+=buf[5]; 47c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project y=y*256;y+=buf[4]; 48c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project y=y*256;y+=buf[3]; 49c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project y=y*256;y+=buf[2]; 50c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project y=y*256;y+=buf[1]; 51c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project y=y*256;y+=buf[0]; 52c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 53c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if(buf[7]&0x80) y=-y; 54c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 55c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project return y; 56c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project} 57c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 58c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Projectint main(int argc,char * argv[]) 59c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project{ 60c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project FILE * f, * cpf, * dpf, * epf; 61c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project BZFILE * cpfbz2, * dpfbz2, * epfbz2; 62c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project int cbz2err, dbz2err, ebz2err; 63c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project int fd; 64c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project ssize_t oldsize,newsize; 65c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project ssize_t bzctrllen,bzdatalen; 66c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project u_char header[32],buf[8]; 67c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project u_char *old, *new; 68c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project off_t oldpos,newpos; 69c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project off_t ctrl[3]; 70c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project off_t lenread; 71c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project off_t i; 72c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 73c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]); 74c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 75c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Open patch file */ 76c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if ((f = fopen(argv[3], "r")) == NULL) 77c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project err(1, "fopen(%s)", argv[3]); 78c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 79c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* 80c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project File format: 81c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 0 8 "BSDIFF40" 82c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 8 8 X 83c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 16 8 Y 84c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 24 8 sizeof(newfile) 85c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 32 X bzip2(control block) 86c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 32+X Y bzip2(diff block) 87c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 32+X+Y ??? bzip2(extra block) 88c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project with control block a set of triples (x,y,z) meaning "add x bytes 89c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project from oldfile to x bytes from the diff block; copy y bytes from the 90c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project extra block; seek forwards in oldfile by z bytes". 91c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project */ 92c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 93c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Read header */ 94c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if (fread(header, 1, 32, f) < 32) { 95c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if (feof(f)) 96c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project errx(1, "Corrupt patch\n"); 97c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project err(1, "fread(%s)", argv[3]); 98c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project } 99c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 100c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Check for appropriate magic */ 101c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if (memcmp(header, "BSDIFF40", 8) != 0) 102c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project errx(1, "Corrupt patch\n"); 103c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 104c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Read lengths from header */ 105c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project bzctrllen=offtin(header+8); 106c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project bzdatalen=offtin(header+16); 107c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project newsize=offtin(header+24); 108c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if((bzctrllen<0) || (bzdatalen<0) || (newsize<0)) 109c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project errx(1,"Corrupt patch\n"); 110c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 111c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Close patch file and re-open it via libbzip2 at the right places */ 112c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if (fclose(f)) 113c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project err(1, "fclose(%s)", argv[3]); 114c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if ((cpf = fopen(argv[3], "r")) == NULL) 115c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project err(1, "fopen(%s)", argv[3]); 116c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if (fseeko(cpf, 32, SEEK_SET)) 117c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project err(1, "fseeko(%s, %lld)", argv[3], 118c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project (long long)32); 119c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL) 120c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err); 121c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if ((dpf = fopen(argv[3], "r")) == NULL) 122c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project err(1, "fopen(%s)", argv[3]); 123c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if (fseeko(dpf, 32 + bzctrllen, SEEK_SET)) 124c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project err(1, "fseeko(%s, %lld)", argv[3], 125c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project (long long)(32 + bzctrllen)); 126c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL) 127c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err); 128c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if ((epf = fopen(argv[3], "r")) == NULL) 129c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project err(1, "fopen(%s)", argv[3]); 130c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET)) 131c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project err(1, "fseeko(%s, %lld)", argv[3], 132c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project (long long)(32 + bzctrllen + bzdatalen)); 133c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL) 134c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err); 135c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 136c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if(((fd=open(argv[1],O_RDONLY,0))<0) || 137c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project ((oldsize=lseek(fd,0,SEEK_END))==-1) || 138c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project ((old=malloc(oldsize+1))==NULL) || 139c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project (lseek(fd,0,SEEK_SET)!=0) || 140c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project (read(fd,old,oldsize)!=oldsize) || 141c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project (close(fd)==-1)) err(1,"%s",argv[1]); 142c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if((new=malloc(newsize+1))==NULL) err(1,NULL); 143c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 144c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project oldpos=0;newpos=0; 145c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project while(newpos<newsize) { 146c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Read control data */ 147c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project for(i=0;i<=2;i++) { 148c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project lenread = BZ2_bzRead(&cbz2err, cpfbz2, buf, 8); 149c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if ((lenread < 8) || ((cbz2err != BZ_OK) && 150c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project (cbz2err != BZ_STREAM_END))) 151c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project errx(1, "Corrupt patch\n"); 152c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project ctrl[i]=offtin(buf); 153c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project }; 154c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 155c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Sanity-check */ 156c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if(newpos+ctrl[0]>newsize) 157c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project errx(1,"Corrupt patch\n"); 158c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 159c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Read diff string */ 160c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project lenread = BZ2_bzRead(&dbz2err, dpfbz2, new + newpos, ctrl[0]); 161c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if ((lenread < ctrl[0]) || 162c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project ((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END))) 163c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project errx(1, "Corrupt patch\n"); 164c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 165c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Add old data to diff string */ 166c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project for(i=0;i<ctrl[0];i++) 167c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if((oldpos+i>=0) && (oldpos+i<oldsize)) 168c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project new[newpos+i]+=old[oldpos+i]; 169c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 170c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Adjust pointers */ 171c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project newpos+=ctrl[0]; 172c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project oldpos+=ctrl[0]; 173c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 174c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Sanity-check */ 175c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if(newpos+ctrl[1]>newsize) 176c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project errx(1,"Corrupt patch\n"); 177c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 178c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Read extra string */ 179c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project lenread = BZ2_bzRead(&ebz2err, epfbz2, new + newpos, ctrl[1]); 180c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if ((lenread < ctrl[1]) || 181c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project ((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END))) 182c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project errx(1, "Corrupt patch\n"); 183c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 184c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Adjust pointers */ 185c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project newpos+=ctrl[1]; 186c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project oldpos+=ctrl[2]; 187c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project }; 188c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 189c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Clean up the bzip2 reads */ 190c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project BZ2_bzReadClose(&cbz2err, cpfbz2); 191c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project BZ2_bzReadClose(&dbz2err, dpfbz2); 192c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project BZ2_bzReadClose(&ebz2err, epfbz2); 193c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if (fclose(cpf) || fclose(dpf) || fclose(epf)) 194c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project err(1, "fclose(%s)", argv[3]); 195c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 196c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project /* Write the new file */ 197c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0666))<0) || 198c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) 199c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project err(1,"%s",argv[2]); 200c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 201c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project free(new); 202c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project free(old); 203c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project 204c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project return 0; 205c285feace7a051368d4c5069cc6e0f30cd769f0dThe Android Open Source Project} 206