Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: third_party/bspatch/mbspatch.cc

Issue 268: Fix binary patching for localized OS. Not sure how it was working till now.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/bspatch/mbspatch.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 * through faithfully. Under *nix, we are always in binary mode, so 202 * through faithfully. Under *nix, we are always in binary mode, so
203 * the following #define turns this flag into a no-op w.r.t. bitwise 203 * the following #define turns this flag into a no-op w.r.t. bitwise
204 * OR. Note that this would be DANGEROUS AND UNSOUND if we used 204 * OR. Note that this would be DANGEROUS AND UNSOUND if we used
205 * _O_BINARY other than as a bitwise OR mask (e.g., as a bitwise AND 205 * _O_BINARY other than as a bitwise OR mask (e.g., as a bitwise AND
206 * mask to check for binary mode), but it seems OK in the limited 206 * mask to check for binary mode), but it seems OK in the limited
207 * context of the following small function. */ 207 * context of the following small function. */
208 #ifndef _O_BINARY 208 #ifndef _O_BINARY
209 # define _O_BINARY 0 209 # define _O_BINARY 0
210 #endif 210 #endif
211 211
212 int ApplyBinaryPatch(const char *old_file, const char *patch_file, 212 int ApplyBinaryPatch(const wchar_t *old_file, const wchar_t *patch_file,
213 const char *new_file) { 213 const wchar_t *new_file) {
214 int ret = 0; 214 int ret = 0;
215 int pfd = open(patch_file, O_RDONLY | _O_BINARY); 215 int pfd = _wopen(patch_file, O_RDONLY | _O_BINARY);
216 if (pfd < 0) return READ_ERROR; 216 if (pfd < 0) return READ_ERROR;
217 217
218 MBSPatchHeader header; 218 MBSPatchHeader header;
219 if (ret = MBS_ReadHeader(pfd, &header)) return ret; 219 if (ret = MBS_ReadHeader(pfd, &header)) return ret;
220 220
221 int ofd = open(old_file, O_RDONLY | _O_BINARY); 221 int ofd = _wopen(old_file, O_RDONLY | _O_BINARY);
222 if (ofd < 0) return READ_ERROR; 222 if (ofd < 0) return READ_ERROR;
223 223
224 struct stat os; 224 struct stat os;
225 if (ret = fstat(ofd, &os)) return READ_ERROR; 225 if (ret = fstat(ofd, &os)) return READ_ERROR;
226 if (os.st_size != header.slen) return UNEXPECTED_ERROR; 226 if (os.st_size != header.slen) return UNEXPECTED_ERROR;
227 227
228 unsigned char *buf = (unsigned char*) malloc(header.slen); 228 unsigned char *buf = (unsigned char*) malloc(header.slen);
229 if (!buf) return MEM_ERROR; 229 if (!buf) return MEM_ERROR;
230 230
231 if (read(ofd, buf, header.slen) != header.slen) return READ_ERROR; 231 if (read(ofd, buf, header.slen) != header.slen) return READ_ERROR;
232 if (CalculateCrc(buf, header.slen) != header.scrc32) 232 if (CalculateCrc(buf, header.slen) != header.scrc32)
233 return CRC_ERROR; 233 return CRC_ERROR;
234 234
235 int nfd = open(new_file, O_WRONLY | O_TRUNC | O_CREAT | _O_BINARY); 235 int nfd = _wopen(new_file, O_WRONLY | O_TRUNC | O_CREAT | _O_BINARY);
236 if (nfd < 0) return READ_ERROR; 236 if (nfd < 0) return READ_ERROR;
237 237
238 MBS_ApplyPatch(&header, pfd, buf, nfd); 238 MBS_ApplyPatch(&header, pfd, buf, nfd);
239 239
240 free(buf); 240 free(buf);
241 close(pfd); 241 close(pfd);
242 close(ofd); 242 close(ofd);
243 close(nfd); 243 close(nfd);
244 return OK; 244 return OK;
245 } 245 }
OLDNEW
« no previous file with comments | « third_party/bspatch/mbspatch.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698