| OLD | NEW |
| 1 /*- | 1 /*- |
| 2 * Copyright 2003-2005 Colin Percival | 2 * Copyright 2003-2005 Colin Percival |
| 3 * All rights reserved | 3 * All rights reserved |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted providing that the following conditions | 6 * modification, are permitted providing that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 | 463 |
| 464 oldpos=0;newpos=0; | 464 oldpos=0;newpos=0; |
| 465 while(newpos<newsize) { | 465 while(newpos<newsize) { |
| 466 /* Read control data */ | 466 /* Read control data */ |
| 467 for(i=0;i<=2;i++) { | 467 for(i=0;i<=2;i++) { |
| 468 cfread(&cf, buf, 8); | 468 cfread(&cf, buf, 8); |
| 469 ctrl[i]=offtin(buf); | 469 ctrl[i]=offtin(buf); |
| 470 }; | 470 }; |
| 471 | 471 |
| 472 /* Sanity-check */ | 472 /* Sanity-check */ |
| 473 if((ctrl[0]<0) || (ctrl[1]<0)) |
| 474 errx(1,"corrupt patch (diff): negative chunk size"); |
| 475 |
| 476 /* Sanity-check */ |
| 473 if(newpos+ctrl[0]>newsize) | 477 if(newpos+ctrl[0]>newsize) |
| 474 errx(1,"corrupt patch (diff): overrun"); | 478 errx(1,"corrupt patch (diff): overrun"); |
| 475 | 479 |
| 476 /* Read diff string */ | 480 /* Read diff string */ |
| 477 cfread(&df, new + newpos, ctrl[0]); | 481 cfread(&df, new + newpos, ctrl[0]); |
| 478 | 482 |
| 479 /* Add old data to diff string */ | 483 /* Add old data to diff string */ |
| 480 for(i=0;i<ctrl[0];i++) | 484 for(i=0;i<ctrl[0];i++) |
| 481 if((oldpos+i>=0) && (oldpos+i<oldsize)) | 485 if((oldpos+i>=0) && (oldpos+i<oldsize)) |
| 482 new[newpos+i]+=old[oldpos+i]; | 486 new[newpos+i]+=old[oldpos+i]; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 513 /* Write the new file */ | 517 /* Write the new file */ |
| 514 if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0644))<0) || | 518 if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0644))<0) || |
| 515 (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) | 519 (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) |
| 516 err(1,"open/write/close(%s)",argv[2]); | 520 err(1,"open/write/close(%s)",argv[2]); |
| 517 | 521 |
| 518 free(new); | 522 free(new); |
| 519 free(old); | 523 free(old); |
| 520 | 524 |
| 521 return 0; | 525 return 0; |
| 522 } | 526 } |
| OLD | NEW |