OLD | NEW |
---|---|
1 /*- | 1 /*- |
2 * Copyright 2003,2004 Colin Percival | 2 * Copyright 2003,2004 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 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 return UNEXPECTED_ERROR; | 79 return UNEXPECTED_ERROR; |
80 | 80 |
81 if (sizeof(MBSPatchHeader) + | 81 if (sizeof(MBSPatchHeader) + |
82 header->cblen + | 82 header->cblen + |
83 header->difflen + | 83 header->difflen + |
84 header->extralen != int(hs.st_size)) | 84 header->extralen != int(hs.st_size)) |
85 return UNEXPECTED_ERROR; | 85 return UNEXPECTED_ERROR; |
86 | 86 |
87 return OK; | 87 return OK; |
88 } | 88 } |
89 | 89 |
90 int | 90 int |
91 MBS_ApplyPatch(const MBSPatchHeader *header, int patchfd, | 91 MBS_ApplyPatch(const MBSPatchHeader *header, int patchfd, |
92 unsigned char *fbuffer, int filefd) | 92 unsigned char *fbuffer, int filefd) |
93 { | 93 { |
94 unsigned char *fbufend = fbuffer + header->slen; | 94 unsigned char *fbufend = fbuffer + header->slen; |
95 | 95 |
96 unsigned char *buf = (unsigned char*) malloc(header->cblen + | 96 unsigned char *buf = (unsigned char*) malloc(header->cblen + |
97 header->difflen + | 97 header->difflen + |
98 header->extralen); | 98 header->extralen); |
99 if (!buf) | 99 if (!buf) |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 ret = CRC_ERROR; | 256 ret = CRC_ERROR; |
257 break; | 257 break; |
258 } | 258 } |
259 | 259 |
260 nfd = _wopen(new_file, O_WRONLY | O_TRUNC | O_CREAT | _O_BINARY); | 260 nfd = _wopen(new_file, O_WRONLY | O_TRUNC | O_CREAT | _O_BINARY); |
261 if (nfd < 0) { | 261 if (nfd < 0) { |
262 ret = READ_ERROR; | 262 ret = READ_ERROR; |
263 break; | 263 break; |
264 } | 264 } |
265 | 265 |
266 MBS_ApplyPatch(&header, pfd, buf, nfd); | 266 ret = MBS_ApplyPatch(&header, pfd, buf, nfd); |
grt (UTC plus 2)
2014/05/13 15:10:06
nice catch. shouldn't this be:
if ((ret = MBS_
deymo
2014/05/13 18:14:40
Yeah, both options work (because this is the last
grt (UTC plus 2)
2014/05/13 18:37:04
oh, ha. i didn't notice that it was while(0). in t
| |
267 } while (0); | 267 } while (0); |
268 | 268 |
269 free(buf); | 269 free(buf); |
270 close(pfd); | 270 close(pfd); |
271 if (ofd >= 0) close(ofd); | 271 if (ofd >= 0) close(ofd); |
272 if (nfd >= 0) close(nfd); | 272 if (nfd >= 0) close(nfd); |
273 return ret; | 273 return ret; |
274 } | 274 } |
OLD | NEW |